无法获取/Nodejs 错误 [英] Cannot GET / Nodejs Error
本文介绍了无法获取/Nodejs 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用此处找到的教程:http://addyosmani.github.io/backbone-fundamentals/#create-a-simple-web-server 并添加以下代码.
I'm using the tutorial found here: http://addyosmani.github.io/backbone-fundamentals/#create-a-simple-web-server and added the following code.
// Module dependencies.
var application_root = __dirname,
express = require( 'express' ), //Web framework
path = require( 'path' ), //Utilities for dealing with file paths
mongoose = require( 'mongoose' ); //MongoDB integration
//Create server
var app = express();
// Configure server
app.configure( function() {
//parses request body and populates request.body
app.use( express.bodyParser() );
//checks request.body for HTTP method overrides
app.use( express.methodOverride() );
//perform route lookup based on url and HTTP method
app.use( app.router );
//Where to serve static content
app.use( express.static( path.join( application_root, 'site') ) );
//Show all errors in development
app.use( express.errorHandler({ dumpExceptions: true, showStack: true }));
});
//Start server
var port = 5000;
app.listen( port, function() {
console.log( 'Express server listening on port %d in %s mode', port, app.settings.env );
});
使用 node server.js
启动服务器后,当我访问 localhost:5000
和我只是想知道是否有人对这个错误非常了解,因为 Express 和 Node 对我来说是新手?
After starting the server with node server.js
I'm getting an error stating Cannot GET /
when I access localhost:5000
and I just wondered if anyone knew much about this error as Express and Node are new to me?
推荐答案
我认为你缺少路由,你需要定义至少一个路由,例如'/'来索引.
I think you're missing your routes, you need to define at least one route for example '/' to index.
例如
app.get('/', function (req, res) {
res.render('index', {});
});
这篇关于无法获取/Nodejs 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文