使用apt安装nodejs,node
sudo apt install nodejs python
安装npmc++
apt install npm npm
源码安装 浏览器
1.下载Nodejs源码bash
wget -c 资源地址 app
-c表示当网络中断恢复后断点续传ssh
下载后解压,进入解压目录tcp
2.生成Makefile
编译须要依赖python环境、c、c++
apt install gcc
apt install python
./configure --prefix=/usr/local/nodejs/
运行python脚本
3.make -j 4 && sudo make install
安装make工具
apt install make
apt install make-guile
-j 4 表示用4个线程去编译
4.配置环境变量
vi ~/.bashrc
修改完后 source ~/.bashrc 使配置生效
env | grep PATH
env显示环境变量
启动node
node
查看nodejs版本
node --version
最简单的http服务
1.使用require引入http模块
2.建立http服务
3.侦听端口
server.js
'use strict' var http = require('http'); var app = http.createServer(function(req,res){ res.writeHead(200,{'Content-Type':'text/plain'}); res.end('HelloWorld\n'); }).listen(8080,'0.0.0.0');
启动Nodejs服务
netstat -ntpl 查询全部tcp端口
node app.js
浏览器访问ip:8080 显示HElloWorld
启动程序的三种方式
node app.js
nohub node app.js
forever start app.js
使用forever启动
1.安装forever
yum -y install forever -g
-g 表示在任何目录下使用forever,若是不加,只能在当前目录使用
若是执行失败
使用 npm config set strict-ssl false
forever start server.js 启动服务
forever stop server.js 关闭服务
ssh root@IP 使用ssh链接