-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
45 lines (39 loc) · 1.47 KB
/
app.js
File metadata and controls
45 lines (39 loc) · 1.47 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
/***************************************************************
* --------------SIMPLE API OF STORE PRODUCTS--------- *
* IN THIS API USER CAN GET ALL PRODUCTS AND THEIR ALL FIELDS *
* USER CAN GET SOME SELECTED FIELDS *
* USER CAN SEARCH USING NAME OF PRODUCT AND COMPANY *
* USER CAN SORT PRODUCTS *
* USER CAN LIMIT PRODUCTS *
* FURTHER DETAILS GOTO README.md *
* *************************************************************/
require('dotenv').config();
//error handler package
require('express-async-errors')
//express
const express = require('express');
const connectDb = require('./db/connect')
//ERROR HANDLER
const errorHandler = require('./middleware/error-handler');
//PAGE NOT FOUND
const pageNotFound = require('./middleware/not-found')
//routes
const productRoutes = require('./routes/products')
const app = express();
const PORT = process.env.PORT || 3000;
//express json
app.use(express.json());
app.use('/api/v1/products', productRoutes)
app.use(pageNotFound);
app.use(errorHandler)
//CONNECTING TO DB AND STARTING SERVER
const start = async() => {
try {
console.log('initializing connection ...');
await connectDb(process.env.MONGO_URL);
app.listen(PORT, () => console.log(`connected to :${PORT}`))
} catch (error) {
console.log(`error :${error}`);
}
}
start();