Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var express = require('express')
- , http = require('http') , path = require('path');
- var app = express();
- // all environments
- app.set('port', process.env.PORT || 5000);
- app.set('views', __dirname + '/views');
- app.set('view engine', 'jade');
- 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());
- }
- // Connect DB
- var dbName = 'MasterData';
- var collections = ['games'];
- var db = require('mongojs').connect(dbName, collections);
- // Setup Routes
- app.get('/', function(req, res)
- {
- res.render('index', {title: "TATA"});
- });
- app.get('/games', function(req, res) {
- db.games.find({}, function(err, games) {
- if (err) { console.log("no games"); }
- res.json(games);
- });
- });
- app.get('/games/:id', function(req, res) {
- var id = req.params.id;
- db.games.find({ "_id" : db.ObjectId(id) }, function(err, games) {
- if (err) { throw err }
- res.json(games);
- });
- });
- // POST
- app.post('/games', function(req, res) {
- res.json(req.body);
- db.games.save(req.body);
- });
- http.createServer(app).listen(app.get('port'), function(){
- console.log('Express server listening on port ' + app.get('port'));
- });
- the json that i stored in MasterData db using games collection is
- [
- {
- "0": {
- "id":" 1234",
- "appid": " 12345678909h1230",
- "name": "mark",
- "gameid": "123456789098g123",
- "os": "Ipad"
- },
- "1": {
- "id":" 5678",
- "appid": " 43215678909h1230",
- "name": "james",
- "gameid": "123456789098g123",
- "os": "Ipad"
- },
- "2": {
- "id":" 9011",
- "appid": " 98015678909h1230",
- "name": "amgela",
- "gameid": "123456789098g123",
- "os": "Ipad"
- },
- "3": {
- "id":" 1213",
- "appid": " 45675678909h1230",
- "name": "gimmy",
- "gameid": "123456789098g123",
- "os": "Ipad"
- },
- "4": {
- "id":" 1415",
- "appid": " 00985678909h1230",
- "name": "jaine",
- "gameid": "123456789098g123",
- "os": "Ipad"
- },
- "_id": "52e0c7ade4b099eb8ffc8487"
- }
- ]
Advertisement
Add Comment
Please, Sign In to add comment