nodejs 配置笔记

编写:围城(solq)

日期:2012-5-5

bolg:http://www.cnblogs.com/solq

1.下载nodejs 包
nodejs.org
2.安装webstorm 开发工具
安装好后 安装 nodejs 
菜单:file->settings->plugins 选择 nodejs安装

3.新建 nodejs 项目。。。会自动帮你配置 express mvc 框架。。。具体用法请看 code吧
静态html文件,放在public 目录下 
点击 run 按钮就运行了。。调试很方便
app.js 是配置文件,很详细了。。请求 url 是要自己配置的。。
也可以手动安装  express
npm install -g express
4.安装 supervisor 每次更改不用重启 node app
https://github.com/isaacs/node-supervisor

安装很简单 cmd
npm install supervisor -g

使用
supervisor app.js

原 webstorm run 配置
C:\Program Files\nodejs\node.exe

5.修改 run 配置
新建个 bat
内容: supervisor %1

webstorm 修改: 菜单 run->edit configurations -> path to node -> 复制你的 bat 路径 如 d:\xxx.bat

 简单入门:

配置 routes

app.get('/', routes.index);
app.get('/hello',routes.hello);
app.get('/test',function(req, res){ // map 静态文件
    fs.readFile(__dirname + '/public/ttt.html', 'utf8', function(err, text){
        res.send(text);
    });
});

 routes/index.js 文件

exports.index = function(req, res){
  res.render('index', { title: 'Express' });//index 为views\index.jade 模板
};
exports.hello = function(req, res){
    res.render('hello', { title: 'xxxxxxxxxxxxxxx' })
};
webstorm 主题修改:
点击:配置按钮
editor->colors&fonts-> saves as 自己的配置,
然后进行修改。。。
C:\Documents and Settings\Administrator\.WebIde40\config\colors 目录会找到你的配置。。。

帖上我的配置。。
https://files.cnblogs.com/solq/solqlayout.xml

express test //即可创建项目
解决linux  Cannot find module 'express'

//cp -r /usr/local/lib/node_modules/* /usr/local/lib/node
ln -s /usr/local/lib/node_modules /usr/local/lib/node
http://stackoverflow.com/questions/5919629/express-module-not-found-when-installed-with-npm

注意:你的项目要有 node_modules 文件夹。。里面要有 express模块
解决winodw Cannot find module
'express' express test 创建后会有提示
$ cd test && npm install
解决方法一:
复制命令运行就可以了,但是每次 install 都要重新下载.........

解决方法二:
直接复制 已生成的 node_modules 的模块。。。。。。。。。。

解决方法三:
复制你的模块到
C:\Program Files\nodejs\node_modules
设置环境变量:
set NODE_PATH=C:\Program Files\nodejs\node_modules;
写死吧。。右击我的电脑。。。。。建议用这种方式。
 
 
 
 
 
原文地址:https://www.cnblogs.com/solq/p/2484897.html