????????????Node.js??mongodb??mongoose??webstorm
????????????????mongoose????????Mongoose??MongoDB????????????????????????????????????????????ο?????http://mongoosejs.com/docs/index.html
????1?????????mongoose??????????????????У????$ npm install mongoose
????2??????mongodb???????app.js??????????????д???
????var mongoose = require('mongoose');
????mongoose.connect('mongodb://localhost/test'); //????????test???????
???????????????????????????????????????????ν?????????????????????????????????е????????????????????????????????????á?
????3????webstorm????????μ?Express App??????????????????express()?????????д???鷳????????app.js???£?

 

/**
* Module dependencies.
*/
var express = require('express')
?? routes = require('./routes')
?? user = require('./routes/user')
?? http = require('http')
?? path = require('path')
?? mongoose = require('mongoose');   //1
var app = express();
// all environments
app.set('port'?? process.env.PORT || 3000);
app.set('views'?? __dirname + '/views');
app.set('view engine'?? 'ejs');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname?? 'public')));
// development only
if ('development' == app.get('env')) {
app.use(express.errorHandler());
}
app.get('/'?? routes.index);
app.get('/log'??routes.login);
app.post('/log'??routes.doLogin);
app.get('/reg'??routes.reg);
app.post('/reg'??routes.doReg);
//mongoose
mongoose.connect('mongodb://localhost/test_db');  //2
http.createServer(app).listen(app.get('port')?? function(){
console.log('Express server listening on port ' + app.get('port'));
});