-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
47 lines (36 loc) · 1.24 KB
/
Copy pathapp.js
File metadata and controls
47 lines (36 loc) · 1.24 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
40
41
42
43
44
45
46
47
const express = require('express');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
const apiroutes = require('./api/user');
const cors = require('cors');
const dot = require('dotenv').config();
var app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: false
}));
app.use(cors());
app.use((req, res, next) => {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', '*');
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
next();
})
// app.use((error, req, res, next) => {
// console.log(error);
// const status = error.statusCode || 500;
// const message = error.message;
// res.status(status).json({ message: message });
// });
//Static folder for uploading files/attachments
app.use(express.static('uploads'))
app.use('/api', apiroutes);
app.get("/", (req, res) => { res.send("Here") })
mongoose.connect(
'mongodb+srv://admin-hrms:' + 'BUTTONS007' + '@cluster0-kldnh.mongodb.net/HRMS?retryWrites=true&w=majority', {
useNewUrlParser: true, useUnifiedTopology: true
}
)
.then(console.log('hello'))
.catch(err => console.log(err))
app.listen(process.env.PORT || 3001);