-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
29 lines (25 loc) · 858 Bytes
/
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
const express = require('express');
const bodyParser = require('body-parser');
const getCSV = require('get-csv');
// create express app
const app = express();
// parse requests of content-type - application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: true }))
// parse requests of content-type - application/json
app.use(bodyParser.json())
//middleware to fetch Csv file and proceed only if it is fetched successfully
app.use('/',function(req, res, next) {
getCSV('https://www.newslaundry.com/sample-data/sample-subscribers.csv')
.then(rows => {
req.subscriptionData = rows;
next();
})
.catch(err => {
res.status(500).send({message:"Error in loading file"});
});
});
require('./app/routes/app.routes.js')(app);
// listen for requests
app.listen(3000, () => {
console.log("Server is listening on port 3000");
});