express get and post code example
Example 1: node js express url parameters
app.get('/api/:version', function(req, res) {
res.send(req.params.version);
});
Example 2: express route parameters
app.get('/users/:userId/books/:bookId', function (req, res) {
res.send(req.params)
})
Example 3: express getting options instead of post
var express = require('express')
, cors = require('cors')
, app = express();
const corsOptions = {
origin: true,
credentials: true
}
app.options('*', cors(corsOptions));
app.listen(80, function(){
console.log('CORS-enabled web server listening on port 80');
});