-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
31 lines (21 loc) · 927 Bytes
/
app.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
'use strict';
// Require dependencies
const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
const mongoose = require('mongoose');
const shortUrl = require('./models/shortUrl');
const app = express(); // Setting up 'express' instance
app.use(bodyParser.json()); // Setting up 'bodyparser' instance
app.use(cors()); // Setting up 'CORS' instance
app.use(express.static(__dirname + '/public'));
// Creates the DB entry
app.get('/new/:urlToShorten(*)', (req, res, next) => {
let { urlToShorten } = req.params; // using ES6 destructuring
return res.json({urlToShorten});
});
//
// Setup port for running server
const port = process.env.PORT || 3000;
// Setting up our server
app.listen(port, () => console.log(`App is running on port ${port}`));