Node.js

Node.js® is a JavaScript runtime built on Chrome’s V8 JavaScript engine. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient.

History

版本 发布时间 维护截至

  • 18.x 2022/04/19 2025/04/30
  • 16.x 2021/4/20 2024/4/30
  • 14.x 2020/4/21 2023/4/30
  • 12.x 2019/4/23 2022/4/30
  • 10.x 2018/4/24 2021/4/30

参考

使用NPM

  • 查看版本 npm -v
  • 查看配置 npm config list
  • 修改镜像 npm install -g mirror-config-china --registry=http://registry.npm.taobao.org
  • Cache files are stored in ~/.npm on Posix, or %AppData%/npm-cache on Windows.

演示:创建Web服务

1
2
3
4
5
6
7
8
9
10
// 创建服务
var http = require('http');

http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello World\n');
}).listen(8888);

// 启动服务
node server.js

使用PM2管理

  • 安装 npm install pm2 -g
  • 启动 pm2 start | stop | restart | delete
  • 监控 pm2 monit
  • 进程列表 pm2 list
  • 使用PM2启动Express.js: pm2 start bin/www