本文链接:https://blog.csdn.net/syosinnsya/article/details/80395121
使用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 //安装
npm uninstall //卸载
npm search //搜索
npm update //更新
这种安装是本地安装,安装在命令行所在的文件夹里。nodejs使用这些依赖时,要用var xx = requires('xxx')去使用。
还可以全局安装:npm install
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