https://github.com/dilane3/core-express-api
Core-express-api is a template for creating api with Nodejs/Express
https://github.com/dilane3/core-express-api
Last synced: about 2 months ago
JSON representation
Core-express-api is a template for creating api with Nodejs/Express
- Host: GitHub
- URL: https://github.com/dilane3/core-express-api
- Owner: dilane3
- Created: 2021-09-15T10:33:39.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-09-15T11:58:33.000Z (almost 5 years ago)
- Last Synced: 2025-02-22T01:26:54.930Z (over 1 year ago)
- Language: JavaScript
- Size: 37.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# core-express-api
**core-express-api** is a template for creating api server application using **nodejs and express** (javascript's technologies).
It offer to you the main structure that you can use for starting your server app. Many folders and files are already created, and the server is already setup and run fine. Let's see what these folders and files contain.
## Structure of the main project
There is so many folders and files in this project, only that you need to start you server application. Let's discover it.
1. **Main file (app.js)**
This file is the entry point of your application, it's here where all the request is handled by your server app.
2. **routes folder**
This Folder store all the routes file of your application. By default there is already one router file named **user.js**, and handles all the request that refers to the user.
code
```javascript
const express = require('express')
const {getAllUsers} = require('../controllers/userController.js')
const authenticationMiddleWare = require("../middlewares/authentication.js")
const route = express.Router()
route.get("/all", authenticationMiddleWare, getAllUsers)
module.exports = route
```
regarding inside of this file, we remark that, there is one route defined which URI `/all`.
We can also see that, this file depends on **getAllUsers** function and **authenticationMiddleWare**.
We will present all those functions below.
3. **controllers folder**
This folder store all controllers that are used for all routes file. One controller is asign to one router handler. It's inside the controller where all the logic is stored.
code
```javascript
const {hashPassword, comparePassword} = require("../helpers/hashPassword.js")
class UserController {
/**
* Get all users
*/
static getAllUsers(req, res) {
res.send("No user found !")
}
}
module.exports = UserController
```
Here we define a class named **UserController** which contains one static function named **getAllUsers** which returns a message to the browser.