Express 4, start template

var express = require('express'); var bodyParser = require('body-parser'); var app = express(); app.use(bodyParser.json()); app.use(function(req, res, next){ res.header('Access-Control-Allow-Origin', '*'); res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE'); res.header('Access-Control-Allow-Methods', 'Content-Type, Authorization'); next(); }); app.post('/login', function(req, res){ console.log(res.body); }); var server = app.listen(3000, function(){ console.log('api listening on port', server.address().port); });

1 Response

Helpful one!

Write a comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.