本文主要介绍nodejs在windows下安装及运行脚本。

安装nodejs

先从nodejs官网:http://nodejs.org/下载对应的系统的安装包,比如用于64位系统的最新0.10.21的x64版本

其他系统可以从http://nodejs.org/download/找到对应的版本进行安装。

直接msi格式全程傻瓜式安装,中间会提示是否把node和npm添加到PATH环境变量里,为了方便使用,直接选择是。

安装完成后会在安装目录出现两个重要的文件node.exe和npm,npm.cmd,以及npm对应的脚本目录node_modules/npm。

同时,在用户目录下(%userprofile%\AppData\Roaming)会有两个目录:

  • npm:全局的模块存放路径,它下面还有一个node_modules目录存放对应的脚本。
  • npm-cache:npm模块的缓存目录,通过npm install命令安装的模块会先下载到缓存目录下

 

安装模块

nodejs通过npm命令对模块进行管理,使用npm install命令来安装模块。

它支持多方式来安装模块:

  • npm install <package Name>:使用模块名称来进行安装模块,如npm install coffee-script。可以从https://npmjs.org/上面找到所有可用的模块。
  • npm install <package Name>@<tag>:安装指定标签的模块,如npm install coffee-script@latest
  • npm install <package Name>@<version>:安装指定版本的模块,如npm install coffee-script@1.0
  • npm install <package Name>@<version range>:安装指定版本范围的模块,如npm install =0.1.0">coffee-script@”>=0.1.0 <0.2.0”
  • npm install [tarball file]:使用tar.gz文件,如:npm install coffee-script.tar.gz
  • npm install [tarball url]:同上,不过是一个网络上的tar.gz文件,如:npm install http://github.com/jashkenas/coffee-script/tarball/master
  • npm install [folder]:一个文件夹名称,如npm install coffee-script/
  • npm install:在文件夹内时使用

其中,通过tar.gz或者文件夹的方式需要根目录下有一个package.json来描述这个模块的信息,如coffee-script模块:https://github.com/jashkenas/coffee-script/blob/master/package.json

以上的方式都是直接把模块安装到站点的node_modules目录下,npm install还有一个参数,用于把模块安装到全局环境中,即安装全局模块。

如npm install coffee-script -g就是把coffeescript安装为全局模块,安装完成之后可以看到%userprofile%\AppData\Roaming\目录下多了几个文件:

  • coffee:指定coffeescript相关的脚本环境等信息
  • coffee.cmd:用于运行coffeescript命令来编译或者做其他事情,如coffee –compile…
  • node_modules/coffee-script目录:具体脚本存放的路径

 

运行模块

通过把模块安装为全局模块,可以直接通过运行脚本。

如coffeescript用来把coffee脚本编译成js脚本:coffee –wc *.coffee,这样会把当前目录下所以的.coffee文件编译成.js文件。

还有经常用来压缩js的uglify-js2:uglifyjs2 --ascii –o test.min.js test.js,把test.js压缩并输出为test.min.js。

 

花了一点时间,对nodejs环境初步了解^_^。

--EOF--

最新文章

  1. vtkQuadratic创建半球面
  2. Oracle11g字符集AL32UTF8修改为ZHS16GBK详解【转】
  3. 【基础】利用thrift实现一个非阻塞带有回调机制的客户端
  4. rsa加密解密
  5. Jquery easyui-combobox 的一个BUG
  6. MySQL+Sphinx实现全文搜索
  7. [摘]string.jion() 解决办法
  8. Python对象体系揭秘
  9. CWnd类
  10. linux 内核分析之list_head
  11. Cocos2d-x 3.1.1 lua-tests 开篇
  12. JS call与apply
  13. smarty的学习计划(2)
  14. html学习笔记 - 标签
  15. Redis报错 Server started, Redis version 3.2.13 Can&#39;t handle RDB format version 9 Fatal error loading the DB: Invalid argument. Exiting.
  16. @Autowired注入报错
  17. CentOS 安装开发环境 并安装coTurn
  18. STM32F105 PA9/OTG_FS_VBUS Issues
  19. js解决浮点数的加减乘除
  20. 使用 Azure CLI 创建和管理 Linux VM

热门文章

  1. 准备开发一款开源NES模拟器
  2. python自我输出源程序
  3. Mysql插入数据为何要加上&quot; ` &quot;(Esc下面那个按键符号)?
  4. android 很多牛叉布局github地址(转)
  5. photoshopcc基础教程
  6. prism4 StockTrader RI 项目分析一些体会
  7. myeclipse项目编码方式彻底设置
  8. 自己对Extjs的Xtemplate的忽略
  9. CAD 二次开发--属性块
  10. XAMARIN +VS2015 ANDROID 开发判断gps 是否打开。