1. 程式人生 > >nodejs v8.9.4 安裝

nodejs v8.9.4 安裝

write command figure 輸入 127.0.0.1 running usr 9.4 fig

一.安裝
環境Centos7.3 64位

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

二.nodejs設置環境變量
vim /etc/profile.d/nodejs.sh
#輸入以下內容
export NODEJS_HOME=/usr/local/nodejs
PATH=$PATH:$NODEJS_HOME/bin

刷新環境變量
source /etc/profile.d/nodejs.sh

三.測試
運行項目web.js
var http = require(‘http‘);

http.createServer(function (req, res) {
res.writeHead(200, {‘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 into 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 is 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(function (socket) {
socket.write(‘Echo server\r\n‘);
socket.pipe(socket);
});

server.listen(1337, ‘127.0.0.1‘);

nodejs v8.9.4 安裝