简体   繁体   中英

Having error with mongoose and expressjs

I'm a newbie about node.js and mongodb, i decided to use expressjs framework
i try to write a web-app by this language, now i meet a trouble about using mongoose i already install mongodb and mongoose by npm, but in file app.js, when i write:

var express = require('express')
, routes = require('./routes')
, mongoose = require('mongoose');
var app = module.exports = express.createServer();

==> server can not run, But when i removed this line mongoose = require('mongoose'); ==> server run.. Please help me, how to use mongoose in express, or another way to connect express with mongodb

Make sure you have mongoose installed locally (in the folder node_modules that is on the same level with your server.js file) OR that it's installed globally.

If that's not the case please paste the error message so we can determine exactly what's the root of the problem.

Add mongoose to your package.json file as a dependency, then run "npm install" from the shell. Should install mongoose and anything else you need. -fs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM