Mac brew安装node 及 npm用法

使用brew安装node,首先先对brew进行检查

brew update
brew doctor

如果报这个错:

Warning: Homebrew's sbin was not found in your PATH but you haveinstalled

formulae that put executables in /usr/local/sbin.

Consider setting the PATH for example like so

  echo 'exportPATH="/usr/local/sbin:$PATH"' >> ~/.bash_profile 

解决方法:

export PATH="/usr/local/bin:$PATH"
source ~/.bash_profile

然后进行安装

brew link node
brew uninstall node
brew install node

安装node成功。

在使用nodejs时,首先要设置一个工作文件夹,并对其初始化和添加各种dependencies。 

创建文件夹后,首先:

npm init

//this utility will walk you through createing a package.json file.
//it covers the most common items, and tries to guess sane defaults.

然后安装各种依赖dependecies,它们会被安装在node_module包里。下面举几个例子。

npm install web3
npm install web3-eth
npm install ethereumjs-tx
npm install fast-csv

语法为:

npm install <module>   //安装
npm uninstall <module>   //卸载
npm search <module>   //搜索
npm update <module>   //更新

这种安装是本地安装,安装在命令行所在的文件夹里。nodejs使用这些依赖时,要用var xx = requires('xxx')去使用。

还可以全局安装:npm install <module> -g,这种安装方式安装在用户目录下,使用时候不能用require方式。

node install -g 才会把module安装到node全局 不加-g默认安装到当前工程 别的工程不可见。

 

注:

fs 是node自带的功能,所以不需要npm install fs

npm 是node.js自带的功能


参考文章: 

npm init node 通过指令创建一个package.json文件及npm安装package.json

https://blog.csdn.net/qq_35441998/article/details/55270816

【链接】nodejs npm install全局安装和本地安装的区别

https://zhidao.baidu.com/question/1382950329488558500.html

【链接】NPM使用介绍

http://www.runoob.com/nodejs/nodejs-npm.html


  • 2
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值