контейнер для хранения
#sudo docker run -dit -p 8080:80 — привилегированный — имя nodejs centos /usr/sbin/init
Контейнер Docker
#sudo docker exec -it nodejs bash
Использование Node.js
#ням обновление
#yum установить sudo vim net-tools
#yum install -y gcc-c++ make
#curl -sL https://rpm.nodesource.com/setup_12.x | судо -E баш -
#sudo yum установить -y nodejs
ทดสอบ
#node -v
#npm -v
# mkdir ~/projects
#cd ~/projects
привет-мир.js
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}/`);
});
#узел hello-world.js &
Сервер работает по адресу http://127.0.0.1:80/
# завиток 127.0.0.1
Привет мир!