Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. var http = require ('http');
  2. var fs = require ('fs');
  3. var mongo = require('mongodb').MongoClient;
  4. var DB;
  5. var express = require('express');
  6. var router = express.Router();
  7. var app = express(); // create our app w/ express
  8. var mongoose = require('mongoose'); // mongoose for mongodb
  9. var morgan = require('morgan'); // log requests to the console (express4)
  10. var bodyParser = require('body-parser'); // pull information from HTML POST (express4)
  11. var methodOverride = require('method-override'); // simulate DELETE and PUT (express4)
  12. var passport = require('passport'); //For Sign up and Login
  13. var LocalStrategy = require('passport-local').Strategy; //For sign up and login
  14. require('./passport.js');
  15.  
  16. // configuration =================
  17.  
  18. mongo.connect('mongodb://localhost:27017/shopialmedia', function (err, db) {
  19. console.log('connected to db');
  20. DB = db;
  21. }); // connect to mongoDB database on our localhost
  22.  
  23. app.use(express.static(__dirname + '/public')); // set the static files location /public/img will be /img for users
  24. app.use(morgan('dev')); // log every request to the console
  25. app.use(bodyParser.urlencoded({'extended':'true'})); // parse application/x-www-form-urlencoded
  26. app.use(bodyParser.json()); // parse application/json
  27. app.use(bodyParser.json({ type: 'application/vnd.api+json' })); // parse application/vnd.api+json as json
  28. app.use(methodOverride());
  29. app.use(passport.initialize());
  30.  
  31. //Our Model
  32. var schema = new mongoose.Schema({ //Our Collection Schema
  33. email : {
  34. type : String,
  35. unique : true,
  36. required : true
  37. },
  38.  
  39. password : {
  40. type : String,
  41. required : true
  42. },
  43.  
  44. firstName : {
  45. type : String,
  46. required : true
  47. },
  48.  
  49. lastName : {
  50. type : String,
  51. required : true
  52. },
  53.  
  54. age : {
  55. type : String,
  56. required : true
  57. }
  58. });
  59. var User = mongoose.model('User', schema); //Our Defined Model, will be used in the routes
  60.  
  61. //Routes =======================
  62.  
  63.  
  64. app.get('/api/users', function(req, res) {
  65. User.find(function(err, users) {
  66. if (err)
  67. res.send(err)
  68.  
  69. res.json(users); // return all todos in JSON format
  70. });
  71. });
  72. app.listen(8080);
  73. console.log("App listening on port 8080");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement