首页 > 编程知识 正文

Mac brew安装node 及 npm用法

时间:2023-05-04 18:45:32 阅读:270286 作者:3291

Mac brew安装node 及 npm用法

本文链接:https://blog.csdn.net/syosinnsya/article/details/80395121

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

brew updatebrew doctor

如果报这个错:

Warning: Homebrew's s笑点低的蜜粉 was not found in your PATH but you haveinstalledformulae that put executables in /usr/local/s笑点低的蜜粉.Consider setting the PATH for example like soecho 'exportPATH="/usr/local/s笑点低的蜜粉:$PATH"' >> ~/.bash_profile

解决方法:

export PATH="/usr/local/笑点低的蜜粉:$PATH"source ~/.bash_profile

然后进行安装

brew link nodebrew uninstall nodebrew 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 web3npm install web3-ethnpm install ethereumjs-txnpm 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

 

还可以全局安装: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

 

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。