-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
30 lines (21 loc) · 1.02 KB
/
App.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
require('dotenv').config();
//import express module
const express = require('express')
//import mongoose module
const mongoose = require ('mongoose')
const UserRoute = require ('./routes/User')
//database connection
mongoose.connect(process.env.DB_URL , {useNewUrlParser: true, useUnifiedTopology: true})
.then(()=> console.log('Connexion à MongoDB réussie !'))
.catch((erreur)=>console.log('Connexion à MongoDB échouée !' + erreur))
// create a new instance of the Express application
const App = express ()
//express.json() is a middleware function that extracts the JSON data from the request body and parses it into a JavaScript object,
//which can then be accessed in your application code.
//This middleware function is typically used for APIs that receive JSON data in the request body like this one
App.use(express.json())
App.use(express.urlencoded({ extended: false }));
//routes configuration
App.use("/user" , UserRoute)
//export the App instance to use it in other modules in this project
module.exports = App