❤️
Nighttime-Stories Basic Setup for the project
- Clone the project
- Run
install to install all dependencies
npm
- Create a file in the folder name .env (It will contain your environment variables)
- In the file set your port and database url. An example is given below
DBURI=mongodb://localhost:27017/my-db PORT=3000
- Ensure MongoDB is installed and running on your machine, so you don't get errors
- Type in your terminal
npm run dev
- No welcome page yet but you should get some json data in your browser when you load "localhost/:3000(or which ever port you entered in your .env)"
nodejs-api-template
A starter Template to build Api's with Express Node and MongoDB.
1. cp .env.example .env
2. npm i
(Make sure you have mongodb installed)
3. npm run dev
Features
- Restful Api
- Swagger Docs
- Auth with Email Confirmation and Password Recovery
- Unit and Integration Tests.
- Modular file configuration and Folder Structure.
- Es-Lint.
- Multiple Enviroments setup (development, staging, production)
Project Structure
C:.
| .env
| .env.example
| .eslintignore
| .eslintrc.json
| .gitignore
| LICENSE
| package-lock.json
| package.json
| README.md
|
+---src
| | app.js
| |
| +---config
| | .gitkeep
| | chalk.js
| | development.js
| | index.js
| | logger.js
| | production.js
| | staging.js
| |
| +---helpers
| | index.js
| |
| +---models
| | | .gitkeep
| | | index.js
| | |
| | \---User
| | User.js
| |
| +---modules
| | \---User
| | +---controllers
| | | index.js
| | |
| | +---policies
| | | index.js
| | |
| | \---routes
| | index.js
| |
| \---router
| index.js
|
\---test
+---integration
| .gitkeep
|
\---unit
.gitkeep
SRC FOLDER
This contains most of the folders and files for the project
Config Folder
Houses all the config files including enviroment configs for development, staging and production.
Models Folder
All your mongoose models are kept here and are required automatically into the index.js in the model folder, which in turn is required into the app.js file.
Test Folder
This contains both folders for integation and unit test files.
Modules Folder
This contains all the modules for your project, etc User, Admin. In every module folder you have 3 sub-folders:
- Controllers
- Policies
- Routes
Controllers
contains all the logic for that specific module.
Policies
contains all the validation middleware for that module.
Routes
contains module route definitions and assembly point for controllers and validation middleware, assigning them to specific routes.