Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var http = require ('http');
- var fs = require ('fs');
- var mongo = require('mongodb').MongoClient;
- var DB;
- var express = require('express');
- var router = express.Router();
- var app = express(); // create our app w/ express
- var mongoose = require('mongoose'); // mongoose for mongodb
- var morgan = require('morgan'); // log requests to the console (express4)
- var bodyParser = require('body-parser'); // pull information from HTML POST (express4)
- var methodOverride = require('method-override'); // simulate DELETE and PUT (express4)
- var passport = require('passport'); //For Sign up and Login
- var LocalStrategy = require('passport-local').Strategy; //For sign up and login
- require('./passport.js');
- // configuration =================
- mongo.connect('mongodb://localhost:27017/shopialmedia', function (err, db) {
- console.log('connected to db');
- DB = db;
- }); // connect to mongoDB database on our localhost
- app.use(express.static(__dirname + '/public')); // set the static files location /public/img will be /img for users
- app.use(morgan('dev')); // log every request to the console
- app.use(bodyParser.urlencoded({'extended':'true'})); // parse application/x-www-form-urlencoded
- app.use(bodyParser.json()); // parse application/json
- app.use(bodyParser.json({ type: 'application/vnd.api+json' })); // parse application/vnd.api+json as json
- app.use(methodOverride());
- app.use(passport.initialize());
- //Our Model
- var schema = new mongoose.Schema({ //Our Collection Schema
- email : {
- type : String,
- unique : true,
- required : true
- },
- password : {
- type : String,
- required : true
- },
- firstName : {
- type : String,
- required : true
- },
- lastName : {
- type : String,
- required : true
- },
- age : {
- type : String,
- required : true
- }
- });
- var User = mongoose.model('User', schema); //Our Defined Model, will be used in the routes
- //Routes =======================
- app.get('/api/users', function(req, res) {
- User.find(function(err, users) {
- if (err)
- res.send(err)
- res.json(users); // return all todos in JSON format
- });
- });
- app.listen(8080);
- console.log("App listening on port 8080");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement