首页 > Web开发 > 详细

nodejs v8.9.4 安装

时间:2018-01-15 14:39:10      阅读:895      评论:0      收藏:0      [点我收藏+]
一.安装
环境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 安装

原文:http://blog.51cto.com/shenshen/2061107

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!