Movatterモバイル変換


[0]ホーム

URL:


9951 explained code solutions for 126 technologies


expressjsHow can I use Express.js to create a query?


Express.js is a web application framework for Node.js that allows you to create a query. To do this, you need to set up a route and a function to handle the query.

For example, this code block will create a query route that will return the value ofqueryParam when aGET request is sent to/query:

// Setup the query routeapp.get('/query', (req, res) => {  // Get the query parameter  const queryParam = req.query.param;  // Send the response  res.send(queryParam);});

When aGET request is sent to/query?param=hello, the response will behello.

The code block above consists of the following parts:

  1. app.get('/query', (req, res) => { - This sets up the query route. It specifies that when aGET request is sent to/query, the following function will be called.
  2. const queryParam = req.query.param; - This gets the query parameter (param) from the request.
  3. res.send(queryParam); - This sends the response. In this case, it's the value ofqueryParam.

For more information on Express.js, see thedocumentation.

Edit this code on GitHub


Join
FreshAll techsGitHubData & Programming blogby Denys Golotiuk

[8]ページ先頭

©2009-2025 Movatter.jp