安装node.js
从http://nodejs.org/ 下载安装程序进行安装。
安装后从开始菜单启动:
Node.js command prompt
安装web开发框架Express
如果需要代理访问网络,先用下面的命令设置代理:
> npm config set proxy=http://192.168.1.1:8080
> npm install express
执行下面命令,安装可执行程序:
>
npm install -g express-generator@3
查看express用法:
> express --help
Usage: express [options] [dir]
Options:
-h, --help
output usage information
-V, --version
output the version number
-e, --ejs
add ejs engine support (defaults to jade)
-H, --hogan
add hogan.js engine support
-c, --css
add stylesheet support (less|stylus|compass) (defaults to plain css)
-f, --force
force on non-empty directory
创建web应用
创建应用easy:
> express
--ejs
easy
根据上述提示完成easy安装
>
cd easy && npm install
启动服务
追加app.listen(3000); 到easy 目录下app.js文件:
app.use(app.router);
app.listen(3000);
app.listen(3000);
console.log("web server started at port:3000, access now: http://localhost:3000/");
用node运行
app.js:
>
node
app.js
接下来, 打开浏览器, 输入地址 http://localhost:3000 , 你就可以看到一个简单的 Welcome
to Express 页面了:
to Express 页面了:
或者不修改app.js用下面命令启动应用:
>npm start
> application-name@0.0.1 start C:\easy> node ./bin/www