Skip to content

azmizar/boilerplate-nodejsexpress-webapi

Repository files navigation

NodeJS + Express WebAPI Project Template

Common Plugins

Runtime

Plugin Name npm i --save Description Links
DotEnv dotenv Loads .env into process.env NPM
ModuleAlias module-alias Register aliases of directories and custom module paths in Node NPM
PathAlias path-alias Register aliases and resolves path from root of application NPM
UUID uuid Generation of RFC4122 UUIDS NPM
Winston winston Universal logging NPM
MomentJS moment Date and time library NPM | WebSite
MomentJS Timezone moment-timezone Timezone library NPM | WebSite
CryptoJS crypto-js Crypto library NPM
Object Mapper object-mapper JSON object mapper NPM
Request request HTTP request library NPM
Request Promise request-promise Promise add-on to Request NPM
Joi joi JSON schema validator NPM
Schema Object schema-object JSON schema definition NPM
Loadash loadash Miscs JS library NPM | WebSite
Split split String split library NPM
ExpressJS express WebAPI library NPM | WebSite
CORS cors Cross-origin resource sharing library NPM
Morgan morgan ExpressJS logging facility NPM
Cookie Parser cookie-parser Cookie parser NPM
JWT jsonwebtoken JWT library NPM
EJS ejs JS template library NPM

Development

Plugin Name npm i --savedev Description Links
Nodemon nodemon NodeJS - watch and auto-restart node app NPM | WebSite
MochaJS mocha JS test framework NPM | WebSite
Expect.JS expect.js Minimalistic BDD assertion toolkit based on should.js NPM
SuperAgent superagent SuperAgent is a small progressive client-side and Node.js HTTP request library NPM
Read Last Line read-last-line Read last line(s) of a file NPM

Standard Operating Procedures (SOP)

Using Boilerplate

  • Get MASTER archive https://github.com/azmizar/boilerplate-nodejsexpress-webapi/archive/master.zip
  • Unzip to a new project folder
  • If project folder is not yet set to a GIT repo
    • Go into the project folder using CMD, GIT BASH, or Powershell
    • git init to initialize GIT local repo
    • git add . to stage all files
    • git commit -m "Initialized from boilerplate" to commit all files
    • git remote add origin $remote_repo$ to set the PUSH and FETCH remote repo
    • git pull to get remote repo branch (will see error with tracking information)
    • git branch --set-upstream-to=origin/master master to track current branch to remote
    • git push -f to force update remote repo
  • If project folder is already a GIT repo, then just commit the changes

Standard Practices

Project Structure

  • common contains shared scripts, modules, classes, services, etc for the entire app to use
  • common-models contains shared models for entire app to use
  • common-error-messages contains error message definitions for entire app
  • common-examples contains simple examples
  • config contains configuration files and services
  • docs contains documentation
  • logs is the default logs folder (can be modified in .ENV)
  • middlewares contains shared Express middlewares
  • public contains static files

App Modules

  • Endpoints should be bundled as modules
  • Take an example of API to manipulate file systems
    • 2 modules, paths and files to work on paths and files respectively
    • Folder name for app module is recommended to be prefix with app-
      • Ex: app-paths and app-files
  • All module related files should be contained within the module folder
  • Anything that need to be shared should be in common- folder or in common folder if it is shared for entire app