Node.js的安装与使用(npm)

22 篇文章 1 订阅
10 篇文章 0 订阅

        Node.js发布于2009年5月,由Ryan Dahl开发,是一个基于Chrome V8引擎的JavaScript运行环境,使用了一个事件驱动、非阻塞式I/O模型,让JavaScript 运行在服务端的开发平台,它让JavaScript成为与PHPPythonPerlRuby等服务端语言平起平坐的脚本语言。Node.js对一些特殊用例进行优化,提供替代的API,使得V8在非浏览器环境下运行得更好,V8引擎执行Javascript的速度非常快,性能非常好,基于Chrome JavaScript运行时建立的平台, 用于方便地搭建响应速度快、易于扩展的网络应用

        但由于Node.js对于开发的贡献对大多数不做开发的人意义不大,但里面的npm软件包管理器却用途比较广,所以本文只向大家讲解如何使用npm。接下来,我就教一教大家如何安装Node.js,如何使用npm。

安装Node.js

Windows环境下安装Node.js

        先去Node.js的官网:Node.js

        选择你需要的版本(LTS版本或者Current),点击下载,打开EXE安装包,等待安装完成。

        再按Windows + R,输入“npm”或“node”,看看能不能起作用,如果弹窗显示这不是命令,那就安装失败,可以重新安装一次,或者看看官方文档。

macOS环境下安装Node.js

        如果你安装了Homebrew,可以直接用以下命令安装:

brew install node

        如果没有,那可以参照我的文章安装:Homebrew安装与配置(macOS),或者在官网下载macOS Installer手动安装。

Linux环境下安装Node.js

        由于Node.js官网对于Linux操作系统只提供Binaries源码包,比较麻烦,所以推荐用Linux自带的软件包管理器(适用于Ubuntu、Debian一类Linux):

curl -sL https://deb.nodesource.com/setup_10.x | sudo bash
sudo apt update
sudo apt -y install gcc g++ make
sudo apt -y install nodejs

        这是适用于CentOS一类Linux的安装方法:

curl --silent --location https://rpm.nodesource.com/setup_10.x | sudo bash
sudo yum clean all
sudo yum -y install nodejs

#如果存在多个nodesource,执行这行脚本再执行上面的脚本:
sudo rm -fv /etc/yum.repos.d/nodesource*

        或者使用Homebrew安装(参考这篇文章):Homebrew安装与配置(Linux)

使用npm

        安装之后,使用就很简单了。这是npm的Usage:

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>
npm help npm       more involved overview

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:
    /Users/wjh/.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.12.2 /usr/local/lib/node_modules/npm

        现在,你就可以使用npm全部的功能了。

        如果你喜欢这篇文章,请别忘了点一个赞,谢谢!你的鼓励是我最大的动力!

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

YoungGeeker

你的鼓励是我最大的动力

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

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

打赏作者

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

抵扣说明:

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

余额充值