Node.js极速入门

Node.js是一个跨平台的JavaScript运行时环境,使用V8引擎,以非阻塞I/O处理大量并发连接。本文涵盖了Node.js的简介、官网、下载、安装和环境变量配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


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 -vnpm -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 -vnode -v命令。

在这里插入图片描述


在这里插入图片描述

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AT阿宝哥

给作者送颗薄荷糖吧!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值