forked from Nayra000/passwordManager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
51 lines (40 loc) · 1.15 KB
/
index.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
40
41
42
43
44
45
46
47
48
49
50
51
require('dotenv').config();
const morgan = require('morgan');
const express = require('express');
const mongoose = require('mongoose');
const userRouter = require('./routers/userRouter');
const passwordRouter = require('./routers/passwordRouter');
const app = express();
// allow express to accept json format data
app.use(express.json());
// HTTP request logger
app.use(morgan('dev'));
// ROUTERS
app.use('/passwords', passwordRouter);
app.use('/users', userRouter);
app.get('/', (req, res) => {
// This code will be executed when a GET request is made to the base URL
res.send('<center><h1>welcome to password manager api</h1></center>');
});
// DB connection URI
const DB = process.env.DATABASE.replace(
'<PASSWORD>',
process.env.DATABASE_PASSWORD,
);
// Connect to DB with mongoose ODM
mongoose
.connect(DB, {
useNewUrlParser: true,
})
.then((con) => {
console.log('DB connecting successful...');
})
.catch((err) => {
console.log('DB connection ERROR!!');
});
// SERVER CONNECTION
app.listen(3000, () => {
console.log('listening on port 3000');
});
// Allow Vercel to turn Express into a serverless function
module.exports = app;