Node.js入门指南

Node.js是一个基于Chrome V8引擎的JavaScript运行时环境,用于服务器端开发。

安装

通过官方安装器

访问Node.js官网下载对应平台的安装包…

通过包管理器

使用nvm、fnm等工具管理多个Node.js版本…

基本概念

事件循环

Node.js采用事件驱动的非阻塞I/O模型…

模块系统

CommonJS和ES模块系统的使用方法…

创建简单服务器

const http = require('http');

const server = http.createServer((req, res) => {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
});

server.listen(3000, () => {
  console.log('Server running at http://localhost:3000/');
});