-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
37 lines (30 loc) · 1.04 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
const express = require('express');
require('dotenv').config();
const bodyParser = require('body-parser');
const routes = require('./routes/index.js');
const mongoose = require('mongoose');
const checkConnection = async () =>{
try {
const conn = await mongoose.connect(process.env.DB_URL);
console.log("Database connected successfully...")
}catch(err) {
console.log(err);
}
}
checkConnection();
const app = express();
// Parse application json
app.use(bodyParser.json());
// Parse application application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({extended: false}));
app.use('/api', routes);
app.get('/', (req, res)=>{
res.status(200).send({ status: 200, message: `Welcome to the API. Go to http://localhost:${PORT}/api` })
});
app.use('**', (req, res)=>{
res.status(200).send({ status: 405, message: 'Resource requested not found on the server' })
});
const PORT = process.env.PORT || 3800;
app.listen(PORT, ()=>{
console.log(`Server listening on port ${PORT}. Go to http://localhost:${PORT}/api`);
})