序
听过JS,听过Node,也听过Node.js,还听过npm,然而并不是很清楚的知道都代表什么,这两天调接口,然后前端同学很忙,就自己把前端代码拿过来跑了,也趁机了解一下这几个概念,下边做个小的总结吧。
Node和Node.js
JS就不用说了,一种解释型语言,前端用的较多,目前也出现在服务器端。
其实Node和Node.js是一个东西,那什么是Node呢?再从JS说起,JS是一种解释型语言,需要一个解析器才可以运行,一般情况下,浏览器就充当了这个解析器的作用,那么对于需要独立运行的JS,Node.js则是其解析器。Node.js是一个事件驱动I/O服务端JavaScript环境,基于Google的V8引擎,V8引擎执行Javascript的速度非常快,性能非常好。
一直在写Python,实际上Python也是需要运行环境的,所以我们运行Python程序之前都要安装一个Python的环境,比方说Python 2.7.11或者Python 3.5.3。这里Node也是一样的。
npm
npm是JS的包管理工具,类似于pip之于Python,实现的功能也是一样的。
nvm
Node的版本管理工具
环境的安装和简单使用
安装nvm(version number可以自定义)
➜ Workspace sudo curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.29.0/install.sh | bash Password: % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 7731 100 7731 0 0 2253 0 0:00:03 0:00:03 --:--:-- 2253 => Downloading nvm from git to '/Users/wang/.nvm' => Cloning into '/Users/wang/.nvm'... remote: Counting objects: 5106, done. remote: Compressing objects: 100% (7/7), done. remote: Total 5106 (delta 2), reused 0 (delta 0), pack-reused 5099 Receiving objects: 100% (5106/5106), 1.43 MiB | 122.00 KiB/s, done. Resolving deltas: 100% (3071/3071), done. Checking connectivity... done. * (HEAD detached at v0.29.0) master => Appending source string to /Users/wang/.zshrc => Close and reopen your terminal to start using nvm ➜ Workspace node zsh: command not found: node ➜ Workspace ls Github khb ➜ Workspace source ~/.nvm/nvm.sh ➜ Workspace node zsh: command not found: node ➜ Workspace nvm install node Downloading https://nodejs.org/dist/v6.3.1/node-v6.3.1-darwin-x64.tar.gz... ######################################################################## 100.0% WARNING: checksums are currently disabled for node.js v4.0 and later Now using node v6.3.1 (npm v3.10.3) ➜ Workspace nvm use node Now using node v6.3.1 (npm v3.10.3) ➜ Workspace nvm -v Node Version Manager Note: <version> refers to any version-like string nvm understands. This includes: - full or partial version numbers, starting with an optional "v" (0.10, v0.1.2, v1) - default (built-in) aliases: node, stable, unstable, iojs, s
npm的使用常用的有:
npm install xxx npm search xxx
node升级到最新版本怎么做
➜ ~ sudo npm install n -g /usr/local/bin/n -> /usr/local/lib/node_modules/n/bin/n /usr/local/lib └── n@2.1.8 ➜ ~ sudo n stable install : node-v8.0.0 mkdir : /usr/local/n/versions/node/8.0.0 fetch : https://nodejs.org/dist/v8.0.0/node-v8.0.0-linux-x64.tar.gz ######################################################################## 100.0% installed : v8.0.0
PS:
再次吐槽一下如果用Markdown写出来再放到cnblogs有点蛋疼,可能需要换个博客了 = =。