var express = require('express');
var app = express();
var bodyParser = require('body-parser');

app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());

var router = express.Router();
router.get('/', function(req, res) { 
    res.json({ message: 'DoIt! API' });   
});

router.route('/user')
  .post(function(req, res){
      console.log("post made on user");
  });
app.use('/api', router);

app.listen(3000, function () {
  console.log('The API server is running on the port 3000 !');  
}); 
var express = require('express');
var app = express();
var bodyParser = require('body-parser');

app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());

var router = express.Router();
router.get('/', function (req, res) {
  res.json({ message: 'DoIt! API' });
});

// Allow CORS
app.use(function(req,res,next) {
  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
  next();
});

// User route
router.route('/user')
  .post(function (req, res) {
    res.json({ success: false, message: 'toto' });
  });

// Define API path
app.use('/api', router);

// Listen the port
app.listen(3000, function () {
  console.log('The API server is running on the port 3000 !');
}); 
Add code comments