我正在使用位于此处的教程:http : //addyosmani.github.io/backbone-fundamentals/#create- a-simple-web-server并添加了以下代码。
// 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我收到一条错误消息,指出Cannot GET /访问时的错误localhost:5000,我只是想知道是否有人对这个错误了解很多,因为Express和Node对我来说是新的?
node server.js
Cannot GET /
localhost:5000
我认为您缺少路线,您需要定义至少一条路线,例如“ /”来建立索引。
例如
app.get('/', function (req, res) { res.render('index', {}); });