-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
39 lines (29 loc) · 1.23 KB
/
app.js
File metadata and controls
39 lines (29 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// app.js
var express = require('express');
var bodyParser = require('body-parser');
var product = require('./routes/product'); // Imports routes for the products
var app = express();
// Set up mongoose connection
//var mongoose = require('mongoose');
//let dev_db_url = 'mongodb://someuser:[email protected]:59073/productstutorial';
//var mongoDB = process.env.MONGODB_URI || dev_db_url;
//mongoose.connect('mongodb://localhost:27017/productstutorials', {
// useNewUrlParser: true
//});
//mongoose.Promise = global.Promise;
//var db = mongoose.connection;
//db.on('error', console.error.bind(console, 'MongoDB connection error:'));
const mongoose = require('mongoose');
const mongoDB = process.env.MONGODB_URI || dev_db_url;
mongoose.connect(mongoDB, {useNewUrlParser: true });
mongoose.Promise = global.Promise;
const db = mongoose.connection;
db.on('error', console.error.bind(console, 'MongoDB connection error:'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use('/products', product);
var port = 4000;
app.listen(port, () => {
console.log('Server is up and running on port numner ' + port);
});