# 建站流程
1. 需求分析
2. 项目依赖初始化
3. 入口文件编码
4. 创建视图
5. 测试前端流程
6. 样式开发,伪造模板数据
7. 设计数据库模型
8. 开发后端逻辑
9. 配置依赖文件
10. 网站开发结束
安装所需的nodejs模块
```
jhw2@ubuntu:~/imooc$ npm install express jade moment mongoose
npm WARN deprecated jade@1.11.0: Jade has been renamed to pug, please install the latest version of pug instead of jade
npm WARN deprecated transformers@2.1.0: Deprecated, use jstransformer
npm WARN deprecated mongodb@2.2.16: Please upgrade to 2.2.19 or higher
moment@2.17.1 node_modules/moment
express@4.14.0 node_modules/express
├── escape-html@1.0.3
├── array-flatten@1.1.1
......
```
目录结构
```
jhw2@ubuntu:~/imooc$ pwd
/home/jhw2/imooc
jhw2@ubuntu:~/imooc$ ls
app.js node_modules views
jhw2@ubuntu:~/imooc$
```
app.js代码
```
var express = require('express');
var port = process.env.PORT || 3000;
var app = express();
app.set('views','./views');
app.set('view engine','jade');
app.listen(port);
console.log('imooc started on port ' + port);
```
运行app.js
```
jhw2@ubuntu:~/imooc$ node app.js
imooc started on port 3000
^C
jhw2@ubuntu:~/imooc$ PORT=4000 node app.js
imooc started on port 4000
^C
jhw2@ubuntu:~/imooc$
```
index.jade代码、detail.jade代码、list.jade代码、admin.jade代码
所在目录imooc/views/...
```
doctype
html
head
meta(charset="utf-8")
title #{title}
body
h1 #{title}
```
app.js代码
```
var express = require('express');
var port = process.env.PORT || 3000;
var app = express();
app.set('views','./views');
app.set('view engine','jade');
app.listen(port);
console.log('imooc started on port ' + port);
//index page
app.get('/',function(req,res){
res.render('index',{
title:'imooc 首页'
});
});
//detail page
app.get('/movie/:id',function(req,res){
res.render('detail',{
title:'imooc 详情页'
});
});
//admin page
app.get('/admin/movie',function(req,res){
res.render('admin',{
title:'imooc 后台录入页'
});
});
//list page
app.get('/admin/list',function(req,res){
res.render('list',{
title:'imooc 列表页'
});
});
```
运行app.js
```
jhw2@ubuntu:~/imooc$ node app.js
imooc started on port 3000
```
在浏览器输入框中输入地址端口号localhost:3000,显示页面,如果是虚拟机可以在浏览器上输入虚拟机的IP地址加端口号
```
imooc 首页
```
网友评论