var express = require('express'),
stylus = require('stylus'),
logger = require('morgan'),
bodyParser = require('body-parser'),
mongoose = require('mongoose');
var env = process.env.NODE_ENV = process.env.NODE_ENV || 'development';
var app = express();
function compile(str, path){
return stylus(str).set('filename', path);
}
app.set('views', __dirname + '/server/views');
app.set('view engine', 'jade');
app.use(logger('dev'));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(stylus.middleware(
{
src: __dirname + '/public',
compile: compile
}
));
app.use(express.static(__dirname + '/public'));
mongoose.connect('mongodb://localhost/multivision');
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error..'));
db.once('open', function callback(){
console.log('multivision db opened');
});
app.get('/partials/:partialPath', function(req, res){
res.render('partials/' + req.params.partialPath);
});
app.get('*', function(req, res) {
res.render('index');
});
var port = 3131;
app.listen(port);
console.log('Listening on port ' + port + '...');
但是当我尝试使用
nodemon server.js
时,它会抛出一个错误:
我应该怎么做才能解决问题?我已经在我的目录下安装了mongoose,使用命令连接错误.. {[MongoError:connect ECONNREFUSED 127.0.0.1:27017] name:'MongoError' message:'connect ECONNREFUSED 127.0.0.1:27017'}
npm install mongoose --save
。是的,有很多类似这样的问题,但没有一个对我有帮助。我是nodejs的新手,可能是缺少某些东西。