one. Installation
Environment Centos7.3 64-bit
wget https://nodejs.org/dist/v8.9.4/node-v8.9.4.tar.gz
CD node-v8.9.4/
./configure--prefix=/usr/local/nodejs
Make
Make install
Two. Nodejs Setting environment variables
vim/etc/profile.d/nodejs.sh
#输入以下内容
Export Nodejs_home=/usr/local/nodejs
Path= $PATH: $NODEJS _home/bin
Refresh Environment Variables
source/etc/profile.d/nodejs.sh
Three. Testing
Run the project Web.js
var http = require (' http ');
Http.createserver (function (req, res) {
Res.writehead ($, {' Content-type ': ' Text/plain '});
Res.end (' Hello world\n ');
}). Listen (1337, ' 127.0.0.1 ');
Console.log (' Server running at http://127.0.0.1:1337/');
To run the server, put the code in a file Example.js and execute it with the node program from the command line:
% Node Example.js
Server running at http://127.0.0.1:1337/
Here are an example of a simple TCP server which listens on port 1337 and echoes whatever you send it:
var net = require (' net ');
var server = Net.createserver (socket) {
Socket.write (' Echo server\r\n ');
Socket.pipe (socket);
});
Server.listen (1337, ' 127.0.0.1 ');
Nodejs v8.9.4 Installation