Node.js????mongodb?????
???????????? ???????[ 2014/12/25 15:11:44 ] ?????????????
????????????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(){
});
|
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11