From 571276253c7955e2b2ca4b5b2a153387f93b8834 Mon Sep 17 00:00:00 2001 From: Julien Gautier Date: Mon, 8 Dec 2025 15:45:07 +0100 Subject: [PATCH] =?UTF-8?q?Suppression=20de=20fichiers=20inutilis=C3=A9s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app.js | 19 ------------------- src/server.js | 24 ------------------------ 2 files changed, 43 deletions(-) delete mode 100644 src/app.js delete mode 100644 src/server.js diff --git a/src/app.js b/src/app.js deleted file mode 100644 index ff3fb4c..0000000 --- a/src/app.js +++ /dev/null @@ -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 diff --git a/src/server.js b/src/server.js deleted file mode 100644 index 8a28974..0000000 --- a/src/server.js +++ /dev/null @@ -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