Skip to content

GeekyAnts/express-typescript

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
September 20, 2018 18:47
September 12, 2018 16:45
October 31, 2019 14:56
August 21, 2018 16:40
January 3, 2022 14:54
September 20, 2018 18:47
April 29, 2021 11:29
September 18, 2018 13:27
August 30, 2018 11:09
Hey There! πŸ™Œ 
🀾 that ⭐️ button if you like this boilerplate. 

express-typescript

A boilerplate for Node.js App.

  • This boilerplate is built using Express.js web framework, and is using Typescript Lang for writing the app's logic.
  • It uses Node's Cluster API, this helps us to take advantage of multi-core systems & to handle the load.
  • For storing custom constant configurations within the process.env - DotEnv package is used.
  • For Database - Repo contains the use of Mongoose (ie. MongoDB object modeling for Node.js).
  • For Cache - Repo contains the use of memory-cache (ie. A simple in-memory cache for node.js).
  • For Routing - Repo contains the use of express-router & have distributed Routes into two files ie. Web Routes & API Routes.
  • For Route Auth Middleware - Web routes are configured with CSRF Token while the API routes are configured with JSON Web Token.
  • For Strategies Auth - Repo contains the use of the Passport.js. Passport.js is compatible with Express.js and is authentication middleware for Node.js.
  • For Logging - Repo uses custom Log class built in middlewares folder, and it creates logs file by date & removes the log files after 'X' days (You can define that 'X' in the .env file).
  • For Handling Exception - Repo contains two classes ie. Handler & NativeEvent.
  • To Log - use Log.info('Your message should go here!'). Other options for logging are Log.warn, Log.error & Log.custom.
  • For views - Repo contains the use of PUG template engine.
  • For background queues - Repo contains the use of Kue. For more details, please review the Queue class.

Contents

Global Requisites

  • node (>= 10.5.0)
  • tsc (>= 3.0.1)
  • typescript (>= 3.0.1)
  • mongoose (>= 3.6.2)
  • redis

App Structure

Note: I am mentioning only files/folders which you need to configure if required

β”œβ”€β”€ dist
β”œβ”€β”€ public
β”œβ”€β”€ src
β”‚   β”œβ”€β”€ controllers
β”‚   β”‚   β”œβ”€β”€ Api
β”‚   β”‚   β”‚   β”œβ”€β”€ Auth
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ Login.ts
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ RefreshToken.ts
β”‚   β”‚   β”‚   β”‚   └── Register.ts
β”‚   β”‚   β”‚   └── Home.ts
β”‚   β”‚   β”œβ”€β”€ Auth
β”‚   β”‚   β”‚   β”œβ”€β”€ Login.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ Logout.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ Register.ts
β”‚   β”‚   β”‚   └── Social.ts
β”‚   β”‚   β”œβ”€β”€ Account.ts
β”‚   β”‚   └── Home.ts
β”‚   β”œβ”€β”€ exception
β”‚   β”‚   β”œβ”€β”€ Handler.ts
β”‚   β”‚   └── NativeEvent.ts
β”‚   β”œβ”€β”€ interfaces
β”‚   β”‚   β”œβ”€β”€ models
β”‚   β”‚   β”‚   └── user.ts
β”‚   β”‚   └── vendors
β”‚   β”‚        β”œβ”€β”€ index.ts
β”‚   β”‚        β”œβ”€β”€ INext.ts
β”‚   β”‚        β”œβ”€β”€ IRequest.ts
β”‚   β”‚        └── IResponse.ts
β”‚   β”œβ”€β”€ middlewares
β”‚   β”‚   β”œβ”€β”€ CORS.ts
β”‚   β”‚   β”œβ”€β”€ CsrfToken.ts
β”‚   β”‚   β”œβ”€β”€ Http.ts
β”‚   β”‚   β”œβ”€β”€ Kernel.ts
β”‚   β”‚   β”œβ”€β”€ Log.ts
β”‚   β”‚   β”œβ”€β”€ Statics.ts
β”‚   β”‚   β”œβ”€β”€ StatusMonitor.ts
β”‚   β”‚   └── View.ts
β”‚   β”œβ”€β”€ models
β”‚   β”‚   └── User.ts
β”‚   β”œβ”€β”€ providers
β”‚   β”‚   β”œβ”€β”€ App.ts
β”‚   β”‚   β”œβ”€β”€ Cache.ts
β”‚   β”‚   β”œβ”€β”€ Database.ts
β”‚   β”‚   β”œβ”€β”€ Express.ts
β”‚   β”‚   β”œβ”€β”€ Locals.ts
β”‚   β”‚   β”œβ”€β”€ Passport.ts
β”‚   β”‚   β”œβ”€β”€ Queue.ts
β”‚   β”‚   └── Routes.ts
β”‚   β”œβ”€β”€ routes
β”‚   β”‚   β”œβ”€β”€ Api.ts
β”‚   β”‚   └── Web.ts
β”‚   β”œβ”€β”€ services
β”‚   β”‚   └── strategies
β”‚   β”‚        β”œβ”€β”€ Google.ts
β”‚   β”‚        β”œβ”€β”€ Local.ts
β”‚   β”‚        └── Twitter.ts
β”‚   └── index.ts
β”œβ”€β”€ views
β”‚   β”œβ”€β”€ includes
β”‚   β”œβ”€β”€ modals
β”‚   β”œβ”€β”€ pages
β”‚   β”œβ”€β”€ partials
β”‚   β”œβ”€β”€ static
β”‚   β”‚   β”œβ”€β”€ css/*.css
β”‚   β”‚   └── js/*.js
β”‚   └── layout.pug
β”œβ”€β”€ .env
β”œβ”€β”€ .gitignore
β”œβ”€β”€ nodemon.json
β”œβ”€β”€ package.json
β”œβ”€β”€ README.md
β”œβ”€β”€ tsconfig.json
└── tslint.json

Install, Configure & Run

Below mentioned are the steps to install, configure & run in your platform/distributions.

# Clone the repo.
git clone https://github.com/GeekyAnts/express-typescript.git;

# Goto the cloned project folder.
cd nodets;
# Without Docker

# Note: It is assumed here that you have MongoDB running in the background and that you have created the database.

# Install NPM dependencies.
# Note: You can review the list of dependencies from the below link.
# https://github.com/faizahmedfarooqui/nodets/network/dependencies
npm install;

# Edit your DotEnv file using any editor of your choice.
# Please Note: You should add all the configurations details
# or else default values will be used!
vim .env;

# Run the app
npm run dev;
# With Docker

# Note: It is assumed here that you have Docker running in the background.

# Run the app in docker as a foreground process
docker-compose up

# Run the app in docker as a background process
docker-compose up -d

List of Routes

# Web Routes:

+--------+-------------------------+
  Method | URI
+--------+-------------------------+
  GET    | /
  GET    | /signup
  POST   | /signup
  GET    | /login
  POST   | /login
  GET    | /logout
  GET    | /account
  GET    | /auth/google
  GET    | /auth/google/callback
  GET    | /auth/twitter
  GET    | /auth/twitter/callback
  GET    | /status-monitor
+--------+-------------------------+

# API Routes:

+--------+-------------------------+
  Method | URI
+--------+-------------------------+
  POST   | /api
  POST   | /api/auth/login
  POST   | /api/auth/register
  POST   | /api/auth/refresh-token
+--------+-------------------------+

Screens

Home / Landing Page

Home / Landing Page

Note: This page has sub-sections, like about-us, contact-us & portfolio

LogIn Page

LogIn Page

Note: LogIn with Providers

SignUp Page

SignUp Page

Note: SignUp with Providers

Dashboard Page

Dashboard Page

With Dropdown Menu

Dashboard Page with Dropdown Menu

Page Not Found Page

Page Not Found Page

Note: In case the requested URI does not exist, app shows this page

Under Maintenance Page

Under Maintenance Page

Note: In case an error is generated, so instead of plain errors we can show the under maintenance page.