app.js 774 Bytes
Newer Older
Muddsair Sharif's avatar
Muddsair Sharif committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
var express = require('express');
var app = express();
var path = require('path');
var serveStatic = require('serve-static');
var bodyParser = require('body-parser');

app.use(serveStatic(path.join(__dirname, 'assets'), { index: false }));
app.use(bodyParser.json());       // to support JSON-encoded bodies
app.use(bodyParser.urlencoded({     // to support URL-encoded bodies
  extended: true
}));

app.get('/', function (req, res) {
  res.send('html');
});

app.get('/json', function(req, res) {
  res.send({
    id: 1
  });
});

app.get('/querystring', function(req, res) {
  res.send(req.query);
});

app.post('/save', function(req, res) {
  res.send(req.body);
});

app.get('/500', function(req, res) {
  res.status(500);
  res.send('error');
});

module.exports = app;