express get post request 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: get post request content express
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
app.post('/', (req, res) => {
console.log('Got body:', req.body);
res.sendStatus(200);
});
app.listen(8080, () => console.log(`Started server at http://localhost:8080!`));