liunx 启动 Node.JS 部署的应用的方法: 进入 Node.JS 部署的应用所在的文件夹下, 使用命令 "pm2 start nodejs 应用文件名" 即可启动应用.
Node.JS 应用在 Linux 服务器中的部署及启动:
1,Node.JS 环境搭建
安装常用软件
sudo apt-get install VIM openssl build-essential libssl-dev wget curl Git
nvm 安装
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash
打开新的窗口
nvm install node v8.1.3 这里也可以下载编译好的压缩包进行安装
nvm use node v8.1.3
nvm alias default v8.1.3 默认版本
安装常用 node 包
2. 创建和部署 hello world
以 root 用户身份在根目录下创建 www 目录, www 目录下创建 myNodeApp 文件夹, 里面就一个文件, App.JS, 内容如下:
- const http = require('http')
- http.createServer(function(req,res) {
- res.writeHead(200,{
- 'Content-Type':'text/plain'
- })
- res.end('hello world')
- }).listen(8081)
- console.log('server test')
(如果你是自己结合 Node.JS 框架如 express 编写的应用 (含有 package.JSON), 则直接将项目代码拷贝至 www 目录下, 进入项目目录如 myNodeApp, 执行命令 NPM install 安装依赖.)
3, 启动 Node.JS 部署的应用:
进入到 www 下 myNodeApp 文件夹下
hello world 测试:
pm2 start App.JS
pm2 list 查看启动的应用
pm2 show hello 查看详细信息
pm2 logs 查看当前信息
pm2 stop hello 停止 hello
pm2 delete hello 删除 hello
如图所示表示启动成功, 输入 hello.86886.wang 就可以看到 hello world 了
来源: http://www.css88.com/qa/node-js/12155.html