Suppression de fichiers inutilisés
This commit is contained in:
-19
@@ -1,19 +0,0 @@
|
|||||||
//import express to use express methods and properties
|
|
||||||
const express = require('express');
|
|
||||||
const routes = require('./routes');
|
|
||||||
|
|
||||||
//create an instance of express
|
|
||||||
const app = express();
|
|
||||||
|
|
||||||
//use express.json() to parse incoming requests with JSON payloads
|
|
||||||
app.use(express.json());
|
|
||||||
app.use(express.urlencoded({ extended: true })); //parse incoming requests with urlencoded payloads
|
|
||||||
|
|
||||||
app.use('/api/v1', routes);
|
|
||||||
|
|
||||||
//catch all routes that are not defined to avoid running into errors when a route is not defined
|
|
||||||
app.use('*', (req, res) => {
|
|
||||||
res.status(404).json({ error: 'Path does not found, try again' });
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports = app; //export app to be used in other files
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
const http = require('http'); // import the http module from node.js core to create a server instance
|
|
||||||
const app = require('./app'); // import the express app from the app.js file
|
|
||||||
const connectDB = require('./services/connectDB');
|
|
||||||
|
|
||||||
const PORT = process.env.PORT || 3000; // set the port number to be used by the server instance
|
|
||||||
|
|
||||||
/* create a server instance using the http.createServer method
|
|
||||||
* there is no right or wrong way to create a server instance weather using the http.createServer method or the app.listen method
|
|
||||||
* I usualy use the http.createServer method because it gives me more control over the server instance like adding a socket.io instance to the server instance
|
|
||||||
*/
|
|
||||||
const server = http.createServer(app);
|
|
||||||
|
|
||||||
// Adding server instance inside a callback function also gives a flexibility to add more logic before starting the server
|
|
||||||
const startServer = () => {
|
|
||||||
// Listen to the server instance on the specified port number
|
|
||||||
connectDB(); // connect to the database before starting the server
|
|
||||||
server.listen(PORT, () => {
|
|
||||||
console.log(
|
|
||||||
`Server is running on port ${PORT} AND NODE_ENV is ${process.env.NODE_ENV}`
|
|
||||||
);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
startServer(); // start the server instance
|
|
||||||
Reference in New Issue
Block a user