节点Express.js 4路由不工作,获取404
我一直试图在我的快车应用程序中debugging我的路线。 请求是未定义的,但不知道为什么。
我正在使用Express 4.0,但运行Express 3.0样式(没有bin / www)。
server.js
var app = require('./app') var port = process.env.PORT || 3000; app.set('port', port); app.listen(app.get('port', function(){ console.log('Express web server is listening on port ' + app.get('port')); }));
app.js
var express = require('express'), path = require('path'), routes = require('./routes/index'), app = express(); app.use('/', routes); app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'jade'); app.use(express.static(path.join(__dirname, 'public'))); module.exports = app;
routes / index.js
var express = require('express'); var router = express.Router(); router.get('/', function(req, res) { res.render('index', { title: 'Express' }); }); module.exports = router;
当我在webstorm的应用程序上运行debugging时,该页面会抛出404页面未find。 当我看着debugging,这里的问题,http请求是未定义的:
确保你的app.listen …如下所示
app.listen(app.get('port'), function() { console.log('Express web server is listening on port ' + app.get('port')); });
- 通过Mongoose,Node.js,MongodDB中的特定属性查找embedded式文档
- jquery ajax基本authentication节点expression
- grunt.task.run()不起作用
- 平均堆栈删除callback
- 如何用安全的REST API开发一个安全的Node.js WebApp?
- 使用navigation.sendBeacon发送应用程序/ json数据,预检成功但不能发布
- 如何在Angular / Node.js / Express中将客户端parameter passing给服务器端
- 如何在Expressjs中进行Web服务调用?
- mongoose默认的sorting顺序