node.js - node的express怎么设置初始页面
ringa_lee
ringa_lee 2017-04-17 11:41:33
0
1
1075

就是怎么配置可以只输入域名后面不带参数,访问默认的页面。类似于asp.net的起始页。

ringa_lee
ringa_lee

ringa_lee

reply all(1)
Peter_Zhu

Can’t this project automatically generated by express be able to achieve such a function? !

There are a few sentences in the automatically generated project app.js

var routes = require('./routes/index');
 ..........
app.use('/', routes);

The content of ./routes/index.js is similar to

var express = require('express');
var router = express.Router();

router.get('/', function(req, res, next) {
  //这里就是生成你默认页面的代码
  //下面这句的意思是用一个叫做index的模板生成页面
  res.render('index', { title: 'Chat' });
});

module.exports = router;
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template