express parse query parameters code example

Example 1: get query parameters in node.js

var express = require('express');
var app = express();

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

app.listen(3000);

Example 2: node.js express post query string

const express = require('express');
const bodyParser = require('body-parser');

const app = express();
app.use(bodyParser.urlencoded({ extended: true }));

// POST /somepost/?name=somename
app.post('/somepost', (req, res) => {
    console.log('Name:', req.query.name);
    res.status(200);
});