var express = require('express');var app = express();
app.get('/endpoint', function(request, response) {var id = request.query.id;response.end("I have received the ID: " + id);});
app.listen(3000);console.log("node express app started at http://localhost:3000");
const express = require("express");const app = express();
const querystring = require("querystring");
// if asArray=false only the first item with the same name will be returned// if asArray=true all items will be returned as an array (even if they are a single item)const asArray = false;app.set("query parser", (qs) => {const parsed = querystring.parse(qs);return Object.entries(parsed).reduce((previous, [key, value]) => {const isArray = Array.isArray(value);if (!asArray && isArray) {value = value[0];} else if (asArray && !isArray) {value = [value];}
previous[key] = value;return previous;}, {});});
app.get("/", function (req, res) {res.send(`Your name is ${(req.query.name || "").length} characters long`);});
app.listen(3000);