、http://nodejs.org/下载node.js运行环境安装
![Windows下Node.js开发环境搭建](http://static.open-open.com/lib/uploadImg/20121125/20121125114619_339.png)
2、打开DOS命令行
.安装express框架
末尾显示如下为安装成功
![Windows下Node.js开发环境搭建](http://static.open-open.com/lib/uploadImg/20121125/20121125114619_872.png)
.安装mysql模块
末尾显示如下为安装成功
![Windows下Node.js开发环境搭建](http://static.open-open.com/lib/uploadImg/20121125/20121125114619_607.png)
3、www.jetbrains.com/webstorm/download/下载WebStorm并安装
.安装nodejs插件
File -> setting -> Plugins -> Browse responsitories ![Windows下Node.js开发环境搭建](http://static.open-open.com/lib/uploadImg/20121125/20121125114619_33.png)
搜索nodejs
![Windows下Node.js开发环境搭建](http://static.open-open.com/lib/uploadImg/20121125/20121125114619_765.png)
双击安装
4、File -> New Project
![Windows下Node.js开发环境搭建](http://static.open-open.com/lib/uploadImg/20121125/20121125114619_688.png)
项目目录结构如下
![Windows下Node.js开发环境搭建](http://static.open-open.com/lib/uploadImg/20121125/20121125114619_345.png)
——app.js
01 | var express = require( 'express' ) |
02 | , routes = require( './routes' ) |
03 | , user = require( './routes/user' ) |
04 | , http = require( 'http' ) |
05 | , path = require( 'path' ); |
09 | app.configure( function (){ |
10 | app.set( 'port' , process.env.PORT || 3000); |
11 | app.set( 'views' , __dirname + '/views' ); |
12 | app.set( 'view engine' , 'jade' ); |
13 | app.use(express.favicon()); |
14 | app.use(express.logger( 'dev' )); |
15 | app.use(express.bodyParser()); |
16 | app.use(express.methodOverride()); |
18 | app.use(express.static(path.join(__dirname, 'public' ))); |
21 | app.configure( 'development' , function (){ |
22 | app.use(express.errorHandler()); |
25 | app.get( '/' , routes.index); |
26 | app.get( '/users' , user.list); |
28 | http.createServer(app).listen(app.get( 'port' ), function (){ |
29 | console.log( "Express server listening on port " + app.get( 'port' )); |
——package.json
02 | "name" : "application-name" , |
——node_modules 文件夹下是各种模块,这里是express框架和jade模版引擎。
——public 文件夹下是各种静态文件。
——routes 文件夹下是各种action。好吧routes是路径的意思,但是我喜欢称作这个叫action。
——index.js
1 | exports.index = function (req, res){ |
2 | res.render( 'index' , { title: 'Express' }); |
——views 文件夹下面是各种模版。
——layout.jade
5 | link(rel='stylesheet', href='/stylesheets/style.css') |
——index.jade