Answers for "nodejs get params"

15

express get query params from url

GET /something?color1=red&color2=blue

app.get('/something', (req, res) => {
    req.query.color1 === 'red'  // true
    req.query.color2 === 'blue' // true
})
Posted by: Guest on July-03-2020
5

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);
Posted by: Guest on May-14-2020
0

get query string javascript nodejs

const querystring = require('querystring');
const url = "http://example.com/index.html?code=string&key=12&id=false";
const qs = "code=string&key=12&id=false";

console.log(querystring.parse(qs));
// > { code: 'string', key: '12', id: 'false' }

console.log(querystring.parse(url));
Posted by: Guest on May-12-2020
0

nodejs get params

const url = require('url');

// new URL object
const current_url = new URL('http://usefulangle.com/preview?id=123&type=article');

// get access to URLSearchParams object
const search_params = current_url.searchParams;

// get url parameters
const id = search_params.get('id');
const type = search_params.get('type');

// "123"
console.log(id);

// "article"
console.log(type);
Posted by: Guest on July-10-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language