Nodejs在Linux的部署和配置

Linux centos-7系统,nodejsnode-v6.10.0-linux-x64

1.nodejs官网(http://nodejs.cn/download/)下载压缩包选择合适自己系统的版本),放到Linux的安装目录下,


 

2.tar -xvf node-v6.10.0-linux-x64解压下载的nodejs压缩包

 

建议用mv node-v6.10.0-linux-x64 node移动重命名文件

3.设置nodejs全局变量,

ln -s /root/node/bin/node /sbin/node

ln -s /root/node/bin/npm /sbin/node

                                            

4.设置环境变量,在根目录下/etc/profile里面添加

export node_home = /root/node

export PATH = $node_home/bin:$PATH

 

5.在工作目录下创建hello.js文件,在里面添加

var http = require('http');

http.createServer(function(req, res){

  res.writeHead(200,{'Content-Type': 'text/plain'});

  res.end('hello world');

}).listen(3030);

console.log("http server is listening at port 3030.");

                                                        

7.node运行hello.js文件,

node hello.js

 

然后在浏览器输入IP地址加端口号输出内容了



评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值