(Please give this a star if this was/is helpful to you. Which might motivate me to do more like this :) )
A StandAlone NodeJS Server Backend app which is connected to MongoDB via Express JS, that responds to API (REST API) requests and perform Authentication checks (if neccessary) with JWT tokens. You can use this as a dedicated Server backend for whatever front-end framework you using (like ReactJS, VueJS, even Vanilla JS). This is a NodeJS Server app connected with MongoDB for saving, manipulating and maintaining the data. The APIs are interactively served at the root level by Swagger. All the APIs can be interactively explored through the Swagger UI.
This App is deployed to Heroku. If you also need to deploy in heroku you can do with the following commands using heroku cli
heroku create
- this command creates a server instance in your heroku account.
git push heroku master
- this command pushes the code from the git repository to heroku's app repository.
heroku ps:scale web=1
- this command scales the web server.
heroku open
- this command opens the app instance in default browser.
All the Environmental files will be ignored by default in Heroku. Visit the app settings page and define the environmental values in Config Vars section
The root
directory contains :
package.json
: file that records important metadata about a project and also defines functional attributes of a project that npm uses to install dependencies, run scripts, and identify the entry point to the package.
.eslintrc
: this is the config file of the linter package that the app is using - eslint
.
.prettierrc
: this is the config file of the prettier package which helps to format the code prettier
.babelrc
: this is the config file of the babel package that helps to make use of ES6+ syntax in app's files babel
.env
: this is the environmental config which is not pushed to any VCS or over network as it may contain senstive data like API keys etc.,
Procfile
: this is the config file for deploying in heroku
src
: this is the starting point of the project. The src
(source) directory contains all the neccessary files that initiate the server, connects the middleware and the database with the server, responds to the incoming API requests etc
The src
directory contains :
-
models
: Models directory contains all the schema files with which the database is designed to save data and return the collection of data. -
controllers
: Controllers directory contains all the controller files with which the functional aspect is written. -
routers
: Routers directory contains all the router files with which the app's router is configured to respond with the controller functions corresponding to the incoming API requests. -
middleware
: Middleware directory contains all the middleware files with which the router is configured to perform any middleware functionality (like checking if the user logged in has authority to view or make changes) before performing the controller logic. -
apis
: Apis directory contains all the objects that are defined in swagger config which are served in Swagger UI to interact with the APIs. -
utils
: Utils directory contains all the utility files which are nothing but the most repetitive block of codes and are saved as template files written with abstraction so that the utility can be integrated anywhere within the app. -
server.js
: server.js is the root file for the server to keep running and initiate the router and establish the connection between the database and server to respond any incoming API requests etc., -
constants.json
: constants.json contains all the static/hard-coded values which are usually strings that are returned if any error occurs or any of the validation fails. This is useful if the app grows and if the constants' valus needed to be changed frequently.
The following scripts
can be run within the root directory of the app.
-
npm i
oryarn
: is used to install all the required dependencies that are in the package.json file to run the app -
npm run dev:server
:yarn start dev:server
: is used to run the server app withsrc/server.js
as entry point in development mode -
npm run local:server
:yarn start local:server
: is used to run the server app withsrc/server.js
as entry point in development mode -
npm run lint:check
oryarn lint:check
: is used to lint all the js files within the app's scope. -
npm run lint:fix
oryarn lint:fix
: is used to fix all the fixable linting errors that eslint returned with.eslintrc
config. -
npm run format:check
oryarn format:check
: is used to check if the styling of all files matches with the.prettierrc
config. -
npm run format:fix
oryarn format:fix
: is used to fix if the styling of any/all file(s) doesn't matches the.prettierrc
config. -
npm run prepare
oryarn prepare
: is used to run thehusky
app which is used to prevent commits if it may contain anyeslint
linting errors orprettier
styling error.