nodejs v8.9.4 安裝

一.安裝
環境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');

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章