-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
39 lines (28 loc) · 1.06 KB
/
server.js
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
const express = require('express');
const app = express();
const path = require('path');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
const config = require('./config');
const base58 = require('./base58.js');
const Url = require('./models/url');
const index = require('./routes/index');
//mongoose.connect('mongodb://' + config.db.host + '/' + config.db.name);
mongoose.connect('mongodb://pooja:[email protected]:57589/url-shortnr');
const db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:not connected'));
db.once('open', function() {
console.log("connected we are")
});
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use('/static', express.static(path.join(__dirname, 'views/static')));
app.get('/', function(req, res){
res.sendFile(path.join(__dirname, 'views/index.html'));
});
app.use('/', index);
const port = process.env.PORT || 8080
var server = app.listen(port, function(){
console.log('Server listening on port', port);
});
module.exports = app;