-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
31 lines (24 loc) · 785 Bytes
/
Copy pathserver.js
File metadata and controls
31 lines (24 loc) · 785 Bytes
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
const express= require('express');
const bodyParser= require('body-parser');
const path= require('path');
const http= require('http');
const app= express();
//api file for interacting with mongoDB.
const api=require('./server/routes/api');
//parser
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
//angular DIST output folder
app.use(express.static(path.join(__dirname, 'dist')));
//api location
app.use('/api', api);
//send all other request to Angular app
app.get('*', (req, res)=>{
res.sendFile(path.join(__dirname, 'dist/index.html'));
});
//set port
const port= process.env.PORT || '3000';
app.set('port', port);
//create server
const server =http.createServer(app);
server.listen(port,()=> console.log(`Running on localhost:${port}`,port));