无法GET / Nodejs错误 [英] Cannot GET / Nodejs Error

查看:112
本文介绍了无法GET / 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 时,我收到一条错误,指出不能GET / ,我只是想知道有没有人知道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', {});
});

这篇关于无法GET / Nodejs错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆