1、Node.js简介
Node.js 是一个开源和跨平台的 JavaScript 运行时环境。 它几乎是任何类型项目的流行工具!
Node.js 在浏览器之外运行 V8 JavaScript 引擎(Google Chrome 的内核)。 这使得 Node.js 的性能非常好。
Node.js 应用程序在单个进程中运行,无需为每个请求创建新的线程。 Node.js 在其标准库中提供了一组异步的 I/O 原语,以防止 JavaScript 代码阻塞,通常,Node.js 中的库是使用非阻塞范式编写的,使得阻塞行为成为异常而不是常态。
当 Node.js 执行 I/O 操作时(比如从网络读取、访问数据库或文件系统),Node.js 将在响应返回时恢复操作(而不是阻塞线程和浪费 CPU 周期等待)。
这允许 Node.js 使用单个服务器处理数千个并发连接,而不会引入管理线程并发(这可能是错误的重要来源)的负担。
Node.js 具有独特的优势,因为数百万为浏览器编写 JavaScript 的前端开发者现在无需学习完全不同的语言,就可以编写除客户端代码之外的服务器端代码。
在 Node.js 中,可以毫无问题地使用新的 ECMAScript 标准,因为你不必等待所有用户更新他们的浏览器,你负责通过更改 Node.js 版本来决定使用哪个 ECMAScript 版本,你还可以通过运行带有标志的 Node.js 来启用特定的实验性功能。
2、官网
官网:https://nodejs.org/en/
3、下载
下载:https://nodejs.org/en/download/
建议下载Windows Binary (.zip)的64Bit版本。
4、安装
将安装包node-v16.14.2-win-x64.zip
直接解压至C:\Program Files\node-v16.14.2-win-x64
目录下,其目录结构如下。
以管理员身份运行cmd
,切换目录至C:\Program Files\node-v16.14.2-win-x64
,键入命令node -v
和npm -v
查看版本:
C:\Program Files\node-v16.14.2-win-x64>node -v
v16.14.2
C:\Program Files\node-v16.14.2-win-x64>npm -v
8.5.0
C:\Program Files\node-v16.14.2-win-x64>
以管理员身份运行cmd
,切换目录至C:\Program Files\node-v16.14.2-win-x64
,键入命令:
npm -h
输出结果如下:
C:\Program Files\node-v16.14.2-win-x64>npm -h
npm <command>
Usage:
npm install install all the dependencies in your project
npm install <foo> add the <foo> dependency to your project
npm test run this project's tests
npm run <foo> run the script named <foo>
npm <command> -h quick help on <command>
npm -l display usage info for all commands
npm help <term> search for help on <term> (in a browser)
npm help npm more involved overview (in a browser)
All commands:
access, adduser, audit, bin, bugs, cache, ci, completion,
config, dedupe, deprecate, diff, dist-tag, docs, doctor,
edit, exec, explain, explore, find-dupes, fund, get, help,
hook, init, install, install-ci-test, install-test, link,
ll, login, logout, ls, org, outdated, owner, pack, ping,
pkg, prefix, profile, prune, publish, rebuild, repo,
restart, root, run-script, search, set, set-script,
shrinkwrap, star, stars, start, stop, team, test, token,
uninstall, unpublish, unstar, update, version, view, whoami
Specify configs in the ini-formatted file:
C:\Users\Administrator\.npmrc
or on the command line via: npm <command> --key=value
More configuration info: npm help config
Configuration fields: npm help 7 config
npm@8.5.0 C:\Program Files\node-v16.14.2-win-x64\node_modules\npm
C:\Program Files\node-v16.14.2-win-x64>
5、环境变量
配置系统环境变量path
,将Node.js的安装根目录C:\Program Files\node-v16.14.2-win-x64
添加到其列表项并保存。
重新打开CMD窗口,在任意路径下测试npm -v
和node -v
命令。