There is ajax request:

$.get('/test', {name : 'Vasya'}); 

How on server node.js using express library, get the value of name?

    1 answer 1

    app.js :

     const express = require('express') const app = express() app.use(express.json()) app.use(express.urlencoded({extended: false})) app.get('/test', (req, res) => { // Получаем параметры GET-запроса let name = req.query.name console.log(name) // Vasya res.send({user_name: name}) }) app.listen(3000) 

    Run: node app.js , make requests along the path http://localhost:3000/test , you can go through the browser and check (request GET ).

    The { name: 'Vasya' } parameters passed during the GET request will be converted to jQuery /test?name=Vasya , and you need to get these parameters (which are in the query query) using req.query . If it were $.post , then through req.body .

    • @Eldar Yusupzhanov read a little more about the theory of what a GET and POST request is, how they differ, how to send such requests, and then there will be no questions how to handle them. - Peter Samokhin