1. nvm的官方叫法:nodejs版本管理工具。
2. nodejs
3. npm
nvm、nodejs、npm的关系:
nvm是爸爸,管理nodejs和npm这一对双胞胎兄弟。npm是哥哥,npm哥哥可以管理node弟弟的东西。
个人是这么理解的,要是有偏差,请指点。
(随着时间变哈 ,这个版本可能会出现变化,自行在github上查看) 复制这些字,到Mac的terminal中,就会安装nvm,安装完成后,还暂时不能用,需要复制它提示的两行代码(就是下图拿箭头标出来的两行代码)来配置环境变量:
完成以后 输入
出现
说明nvm安装成功。
第一步:打开终端,输入以下命令安装Homebrew
第二步:安装node,在终端输入以下命令
brew install node
第三步 查看node安装成功与否
node -v
以上三步 node就安装成功了
程序测试
第二步:用终端找到其所在的目录运行
第三步:通过浏览器进行访问localhost:5000,返回数据
第四步:前端就可以通过调用这个接口进行数据解析了,并且可以在当前页面进行数据展示了.
是不是很简单,如果之前做过web服务接口开发的,这个应该不会陌生,甚至来说非常简单了.
npm install <package_name>:这个命令将在当前目录中创建node_modules目录(如果尚不存在),并将该软件包下载到该目录。该命令默认本地安装。
npm install -g <package>:全局安装包。
dependencies和devDependencies指定了项目依赖的包。
dependencies:这些包在生产中需要。
devDependencies:这些包用于开发和测试。
npm update -g <package>:更新全局软件包。npm update -g:更新所有的全局软件包。npm outdated -g --depth=0:找出需要更新的包。
npm uninstall <package>:从node_modules目录中移除一个包。
npm uninstall -g <package>:卸载全局软件包。
总结:本地命令加上-g就是全局命令。
es6 javascript的ESLint 代码检测
ESLint 是一个语法规则和代码风格的检查工具,可以用来保证写出语法正确、风格统一的代码。
首先,安装 ESLint。
然后,安装 Airbnb 语法规则,以及 import、a11y、react 插件。
最后,在项目的根目录下新建一个.eslintrc文件,配置 ESLint。
现在就可以检查,当前项目的代码是否符合预设的规则。
使用 ESLint 检查这个文件,就会报出错误。
上面代码说明,原文件有五个错误,其中两个是不应该使用var命令,而要使用let或const;一个是定义了变量,却没有使用;另外两个是行首缩进为 4 个空格,而不是规定的 2 个空格。
I don’t like to install things as a root user. If it’s possible to install something in my home directory, why not use it?
First, we need to tell NPM that it should install everything in ~/.npm directory.
Now every time when you install NPM package using -g option it will install it in ~/.npm directory. You don’t need the root access to do it. All executables will be in ~/.npm/bin directory. For example if I install ESLint using npm install -g eslintcommand then it will be possible to run eslint command from terminal using full path:
It’s inconvenient, right? It’s better to be able to use just eslint command. To achieve that we need to modify ~/.bash_profilefile. Find in this file line which starts with PATH= and add ~/.npm/bin at the end of the line. In my ~/.bash_profile file it looks like this:
If the line with PATH doesn’t exist then you can add it:
Now you need to apply changes.
And it’s done. You should be able to run eslint without specifying the full path to the file.
Quick tip about PyCharm. PyCharm needs a full path to the ESLint directory, not to ESLint executable file. In settings you need to use~/.npm/lib/node_modules/eslint path.
The error you are facing is because your configuration is not present. To configure the eslint type
eslint --init
then configure as your requirement.