/nodejs-express-template

A personal starter template for Node.js / Express.js server application

Primary LanguageJavaScriptMIT LicenseMIT

Node.js Server App Template

A template with full RESTful user account management for user-account based web apps

  • Database / Data store: MongoDB,
  • Server app: Node.js, Express.js
  • Views: EJS

Features of this template

Resource-based hierarchy

Breaking the server directory structure into resources of business logic each with its inner MVC framework (i.e. product-centric) instead of the usual MVC monolithic framework: https://github.com/i0natan/nodebestpractices/blob/master/sections/projectstructre/breakintresources.md

Local login strategy

Each user account store both password salt and hash in a version-specific strategy to allow for future implementations of more secure password encryption/one-way-encoding strategies while allowing for backward compatibility of accomodating existing users with encrypted/one-way-encoded passwords stored with older strategies.

Style guide

Uses AirBNB enforced by eslint.

Standardised request-response structure

All requests and responses mostly follow the guidelines of JSON API to allow for consistent data models while having the benefit of a standardised interface via HTTP between client and server applications, either internal or external.

Server-side static view rendering using EJS

Each resource has its own set of /views/{resource} and SHOULD be located within a folder with the name {resource} within its own views/ folder. All of the views/ folders for each initalised component will share the hierarchy, and this is to prevent conflicting file pointers during res.render, e.g. server/resources/users/views/index.ejs refer to the same file as client/views/index.ejs.

Server app

Dependencies:

Developer dependencies:

Client app (web)

Local development

  1. On project root level, install packages: npm install. npm manages both server and client resource dependencies.
  2. Run npm start or nodemon if you have installed it via npm globally on your machine.

Deployment

Set up RDBs

Set up MongoDBs

To set up a remote MongoDB, these are some options:

Create the following tables:

  • users

References

Other notes