A simple and improved api with ExpressJS.
Dependencie | Version |
---|---|
cookie-parser | ~1.4.4 |
cors, | ^2.8.5 |
dotenv | ^16.0.2 |
express | ~4.16.1 |
morgan | ~1.9.0 |
nodemon | ^2.0.2 |
First let's clone the repository.
$ git clone https://github.com/Ahosall/express-api-template.git
Go to the directory where the project was cloned and we will install the dependencies.
$ npm install
To start the project there are two ways:
-
Production:
$ npm start
-
Development:
$ npm run dev
I made some changes in the structure of both the code and the folders. The routes are in the src > routes folder. To keep a pattern of files I made a treatment to get the first name of the file.
Example:
clients.route.js
The route in the middle of the names is not mandatory, it's just a way of organizing :>
The code inside each file follows the following structure:
module.exports = [
{
path: "/", // Path of the route
method: "GET", // Method to execute the route
router: (req, res) => { // Where the magic happens~
res.json({message: "Hiii, world!"})
},
},
]
I did it this way to avoid having to import the router function from express... and to maintain a greater view. :>
Well, controllers and models follow the same patterns as always, feel free to create an issue with a new way of programming! :>
If you find bugs, report them in the issues. \( ̄︶ ̄*\)
This project is licensed under the MIT License!
All forms of contact are on my profile!