我基本上按照本教程构建了我的第一个nodeJS应用程序
http://scotch.io/bar-talk/setting-up-a-mean-stack-single-page-application
当输入" localhost"时,它会给我这样的错误
TypeError: Object function parseUrl(req){
var parsed = req._parsedUrl
if (fresh(req, parsed)) {
return parsed
}
parsed = fastparse(req.url)
if (parsed.auth && !parsed.protocol && parsed.href.indexOf('//') !== -1) {
// This parses pathnames, and a strange pathname like //r@e should work
parsed = fastparse(req.url.replace(/@/g, '%40'))
}
return req._parsedUrl = parsed
} has no method 'original'
at serveStatic (/home/robin/Desktop/node/node_modules/express/node_modules/serve- static/index.js:63:32)
at Layer.handle [as handle_request] (/home/robin/Desktop/node/node_modules/express/lib/router/layer.js:82:5)
at trim_prefix (/home/robin/Desktop/node/node_modules/express/lib/router/index.js:271:13)
at /home/robin/Desktop/node/node_modules/express/lib/router/index.js:238:9
at Function.proto.process_params (/home/robin/Desktop/node/node_modules/express/lib/router/index.js:313:12)
at /home/robin/Desktop/node/node_modules/express/lib/router/index.js:229:12
at Function.match_layer (/home/robin/Desktop/node/node_modules/express/lib/router/index.js:296:3)
at next (/home/robin/Desktop/node/node_modules/express/lib/router/index.js:190:10)
at methodOverride (/home/robin/Desktop/node/node_modules/method-override/index.js:63:14)
at Layer.handle [as handle_request] (/home/robin/Desktop/node/node_modules/express/lib/router/layer.js:82:5)
我不知道它是什么。 我的后端代码:
"express": "^4.10.4"
index.js用于初始化整个应用程序
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var methodOverride = require('method-override');
var mongoose = require('mongoose');
var db = require('./config/db');
var port = process.env.PORT || 8080;
mongoose.connect(db.url);
app.use(bodyParser.json());
app.use(bodyParser.json({ type: 'application/vnd.api+json' }));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(methodOverride('X-HTTP-Method-Override'));
app.use(express.static(__dirname + '/public'));
require('./app/routes')(app); // configure our routes
app.listen(port);
console.log('Magic happens on port ' + port);
exports = module.exports = app;
nerd.js
var mongoose = require('mongoose');
module.exports = mongoose.model('Nerd', {
name : {type : String, default: ''}
});
// app / routes.js
// grab the nerd model we just created
var Nerd = require('./models/nerd');
module.exports = function(app) {
app.get('/api/nerds', function(req, res) {
// use mongoose to get all nerds in the database
Nerd.find(function(err, nerds) {
// if there is an error retrieving, send the error.
// nothing after res.send(err) will execute
if (err)
res.send(err);
res.json(nerds); // return all nerds in JSON format
});
});
// route to handle creating goes here (app.post)
// route to handle delete goes here (app.delete)
// frontend routes =========================================================
// route to handle all angular requests
app.get('*', function(req, res) {
res.sendfile('./public/views/index.html'); // load our public/index.html file
});
};
感谢您的帮助!!