dileephell

Untitled

Jan 23rd, 2014
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var express = require('express')
  2. , http = require('http') , path = require('path');
  3.  
  4. var app = express();
  5.  
  6. // all environments
  7. app.set('port', process.env.PORT || 5000);
  8. app.set('views', __dirname + '/views');
  9. app.set('view engine', 'jade');
  10. app.use(express.favicon());
  11. app.use(express.logger('dev'));
  12. app.use(express.bodyParser());
  13. app.use(express.methodOverride());
  14. app.use(app.router);
  15. app.use(express.static(path.join(__dirname, 'public')));
  16.  
  17. // development only
  18. if ('development' == app.get('env'))
  19. {
  20. app.use(express.errorHandler());
  21. }
  22.  
  23. // Connect DB
  24. var dbName = 'MasterData';
  25. var collections = ['games'];
  26.  
  27. var db = require('mongojs').connect(dbName, collections);
  28.  
  29. // Setup Routes
  30. app.get('/', function(req, res)
  31. {
  32. res.render('index', {title: "TATA"});
  33. });
  34.  
  35. app.get('/games', function(req, res) {
  36. res.send('Welcome to Games!');
  37. });
  38.  
  39. app.get('/games/:id', function(req, res) {
  40. var id = req.params.id;
  41. db.games.find({ "_id" : db.ObjectId(id) }, function(err, games) {
  42. if (err) { throw err }
  43. res.json(games);
  44. });
  45. });
  46.  
  47. // POST
  48. app.post('/games', function(req, res) {
  49. res.json(req.body);
  50. db.games.save(req.body);
  51. });
  52.  
  53.  
  54.  
  55.  
  56. http.createServer(app).listen(app.get('port'), function(){
  57. console.log('Express server listening on port ' + app.get('port'));
  58. });
  59.  
  60.  
  61. the json that i stored in MasterData db using games collection is
  62.  
  63.  
  64. [
  65. {
  66. "0": {
  67. "id":" 1234",
  68. "appid": " 12345678909h1230",
  69. "name": "mark",
  70. "gameid": "123456789098g123",
  71. "os": "Ipad"
  72. },
  73. "1": {
  74. "id":" 5678",
  75. "appid": " 43215678909h1230",
  76. "name": "james",
  77. "gameid": "123456789098g123",
  78. "os": "Ipad"
  79. },
  80. "2": {
  81. "id":" 9011",
  82. "appid": " 98015678909h1230",
  83. "name": "amgela",
  84. "gameid": "123456789098g123",
  85. "os": "Ipad"
  86. },
  87. "3": {
  88. "id":" 1213",
  89. "appid": " 45675678909h1230",
  90. "name": "gimmy",
  91. "gameid": "123456789098g123",
  92. "os": "Ipad"
  93. },
  94. "4": {
  95. "id":" 1415",
  96. "appid": " 00985678909h1230",
  97. "name": "jaine",
  98. "gameid": "123456789098g123",
  99. "os": "Ipad"
  100. },
  101. "_id": "52e0c7ade4b099eb8ffc8487"
  102. }
  103. ]
Advertisement
Add Comment
Please, Sign In to add comment