node.js

node app.js - будет выполнен код из файла
просто node - можно писать код прям в командную строку

============

После успешной установки вы можем ввести в командной строке/терминале команду node -v, и нам отобразится текущая версия node.js:

miltorg@miltorg-linux:~$ node -v
v8.10.0
miltorg@miltorg-linux:~$

------------------------

Этот код запускает сервер:

const http = require("http");
http.createServer(function(request,response){

response.end("Hello NodeJS!");

}).listen(3000, "127.0.0.1",function(){
console.log("Сервер начал прослушивание запросов на порту 3000");
});

------------------------

Проверить: http://localhost:3000

-------------------

const http = require("http");
  
http.createServer(function(request, response){
      
    response.setHeader("Content-Type", "text/html");
    response.write("<!DOCTYPE html>");
    response.write("<html>");
    response.write("<head>");
    response.write("<title>Hello Node.js</title>");
    response.write("<meta charset=\"utf-8\" />");
    response.write("</head>");
    response.write("<body><h2>Привет миг</h2></body>");
    response.write("</html>");
    response.end();
}).listen(3000);


https://metanit.com/web/nodejs/3.1.php
Там есть пример простейшей маршрутизации

---------------------
Это тоже сервер:
// Загружаем модуль http
const http = require('http');

// Создаем web-сервер с обработчиком запросов
const server = http.createServer((req, res) => {
console.log('Начало обработки запроса');
// Передаем код ответа и http-заголовки
res.writeHead(200, {
'Content-Type': 'text/plain; charset=UTF-8'
});
res.end('Hello world!');
});

// Запускаем web-сервер
server.listen(3000, '127.0.0.1', () => {
console.log('Сервер запущен http://127.0.0.1:3000/');
});

------------------------
const http = require("http");

const hostname = "127.0.0.1";
const port = 3000;

const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader("Content-Type", "text/plain");
res.end("Hello World\n");
});

server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});

---------------------

Обновление

sudo npm cache clean -f
[sudo] пароль для miltorg:
Попробуйте ещё раз.
[sudo] пароль для miltorg:
npm WARN using --force I sure hope you know what you are doing.
miltorg@miltorg-linux:~$ sudo npm install -g n
/usr/local/bin/n -> /usr/local/lib/node_modules/n/bin/n
/usr/local/lib
└── n@6.5.1

miltorg@miltorg-linux:~$ n latest

installing : node-v14.4.0
mkdir : /usr/local/n/versions/node/14.4.0
mkdir: невозможно создать каталог «/usr/local/n»: Отказано в доступе

Error: sudo required (or change ownership, or define N_PREFIX)

miltorg@miltorg-linux:~$ sudo n latest

installing : node-v14.4.0
mkdir : /usr/local/n/versions/node/14.4.0
fetch : https://nodejs.org/dist/v14.4.0/node-v14.4.0-linux-x64.tar.xz
installed : v14.4.0 (with npm 6.14.5)

Note: the node command changed location and the old location may be remembered in your current shell.
old : /usr/bin/node
new : /usr/local/bin/node
To reset the command location hash either start a new shell, or execute PATH="$PATH"

miltorg@miltorg-linux:~$ node -v
v14.4.0
miltorg@miltorg-linux:~$