Basic template to get your project started from scratch!
👨🏻💻 Hey coder! In this repository you will find a basic schema structure to start your own REST API. 👨🏻💻 This schema is made by some best practices I encountered and think they are pretty usefull to make your code nicer and organized.
The following dependecies are used in the project
Dependencies:
- cors - Node.js CORS middleware
- dotenv - Loads environment variables from .env file
- express - Fast, unopinionated, minimalist web framework
- helmet - Help secure Express/Connect apps with various HTTP headers
- jsonwebtoken - JSON Web Token implementation (symmetric and asymmet
- morgan - HTTP request logger middleware for node.js
- cookie-parser - Parse HTTP request cookies
- compression - Node.js compression middleware
- express-async-handler - Express Error Handler for Async Functions
Developer dependencies:
- eslint - An AST-based pattern checker for JavaScript.
- eslint-config-airbnb-base - Airbnb's base JS ESLint config, following our styleguide
- eslint-plugin-import - Import with sanity.
- mocha - Simple, flexible, fun test framework
- nodemon - Simple monitor script for use during development of a node.js app.
- supertest - SuperAgent driven library for testing HTTP servers
- babel - The compiler for next generation JavaScript
- Clone the repository
git clone https://github.com/boralbgra/express-api-template.git
- Install dependecies
npm install
- Run it!
npm run dev
.
├── ...
├── src # Source files
│ ├── api # api directory including all default shcema
│ │ ├── controllers # express routes functions
│ │ ├── db # functions that works over the DDBB (updates, deletes, lists..)
│ │ ├── middlewares # express middlewares (jsonwebtoken...)
│ │ ├── routes # express routes declaration
│ │ └── scripts # backend scripts
│ ├── config # config file
│ │ ├── db # contains all DDBB config files
│ │ ├── routes # exports all routes globally
│ ├── app.js # express app server
│ └── index.js # starts the server (app.js) in the port established or in a default port
├── test # Test files (alternatively `spec` or `tests`)
└── ...
In each folder of the api, there is an index file. In that file all elements are imported and exported, in order to make easier the import list, as an only import instead of X different imports.
.
├── api # api directory including all default shcema
│ ├── controllers
│ │ └── index.js # all controllers imported and exported as one object
│ ├── db
│ │ └── index.js # all db imported and exported as one object
│ ├── middlewares
│ │ └── index.js # all middlewares imported and exported as one object
│ ├── routes
│ │ └── index.js # all routes imported and exported as one object
│ └── scripts
│ └── index.js # all scripts imported and exported as one object
└── ...
.
├── ...
├── src # Source files
├── test # Test files (alternatively `spec` or `tests`)
│ ├── app.test.js # Unit tests for app.js
│ └── hello.routes.test.js # Unit tests for hello.routes.js
└── ...
- 1.0.4
- Renamed all index files to
index.js
for import purposes, and updatedconfig
folder
- Renamed all index files to
- 1.0.3
- Added
express-async-handler
andcompression
packages
- Added
- 1.0.2
- Add
README.md
- Add
- 1.0.1
- The first proper release
- 1.0.0
- Work in progress
A mention to CJ R., for the following repository as a guidance for doing the base of this template.
Distributed under the MIT license. See LICENSE
for more information.