Skip to content

Node Express TypeScript Starter is a boilerplate for building scalable applications with Node.js and Express. It includes essential packages like Axios, Mongoose, JWT, and testing support using Jest and Supertest. The project is also configured with ESLint and Prettier for consistent code quality.

Notifications You must be signed in to change notification settings

usmanshaikh/node-express-typescript-starter

Repository files navigation

Node Express TypeScript Starter

Node Express TypeScript Starter is a boilerplate for building scalable applications with Node.js and Express. It includes essential packages like Axios, Mongoose, JWT, and testing support using Jest and Supertest. The project is also configured with ESLint and Prettier for consistent code quality.


Table of Contents


Project Overview

This project serves as a scalable starting point for building RESTful APIs with Node.js, Express, and TypeScript. It is ideal for rapid development of web services with essential security, logging, and testing features. The boilerplate includes support for user authentication, JWT tokens, and database connections with MongoDB and Redis.


Technologies Used

  • Node.js: Backend runtime environment.
  • TypeScript: Strongly typed programming language for better maintainability.
  • MongoDB: NoSQL database for data storage and management.
  • Redis: In-memory data store used for caching and session management.
  • Docker: Containerization platform for consistent deployments across environments.
  • Jest: Testing framework for unit and integration tests.
  • Morgan: HTTP request logger middleware for better monitoring.
  • ESLint & Prettier: Code quality and formatting tools to maintain consistent code style.

Installation

  1. Clone the repository:
    git clone <repository-url>
    cd <project-folder>
  2. Install dependencies:
    npm install
  3. Create an .env file using .env.example as a template:
    cp .env.example .env
  4. Run the application:
    npm run watch

Project Structure

.vscode/
build/
coverage/
logs/
node_modules/
src/
tests/
Dockerfile
docker-compose.yml
package.json
README.md

Folder Descriptions

.vscode/

Configuration files for Visual Studio Code (e.g., settings, launch configurations).

build/

Compiled production build files (generated during build processes).

coverage/

Coverage reports for testing.

logs/

Logs generated by the application (such as HTTP requests, errors, etc.).

src/

Main application source code.

config/

Application configuration files (e.g., config.ts, logger.ts, redisClient.ts).

constants/

Global constants, such as messages or application-wide values.

controllers/

Controllers handle HTTP requests and business logic for routes.

database/

Database-related logic and initialization files (including Mongoose setup).

helpers/

Utility functions like error handling, JWT helpers, and response formatting.

middlewares/

Custom middleware for authentication, error handling, rate limiting, and validation.

models/

Database models and schema definitions.

routes/

Route handlers that define the API endpoints.

services/

Business logic and service layers interacting with models and external services.

validations/

Validation schemas and logic for API request payloads.

Main Files

  • app.ts: Application entry point, including middleware and route registration.
  • server.ts: Server initialization and startup logic.

tests/

Unit and integration tests, along with test setup files.

.env / .env.example

Environment variable configurations.

.eslintignore / .eslintrc

ESLint configuration and ignored files.

.prettierignore / .prettierrc

Prettier configuration and ignored files.

jest.config.js

Configuration file for Jest testing framework.


Available Scripts

In the project directory, you can run the following scripts:

npm start

Build the project and then start the server.

npm run start

npm run build

Clean previous builds and compile the TypeScript code.

npm run build

npm run serve

Run the compiled server using Node.js.

npm run serve

npm run watch

Run the TypeScript compiler and the Node.js server in "watch" mode, meaning it will automatically rebuild and reload the server whenever you change a file.

npm run watch

npm run watch-node

Run nodemon on the built server files, allowing the server to restart automatically whenever a change is detected.

npm run watch-node

npm run clean

Clean the build directory before rebuilding.

npm run clean

npm run build-ts

Compile the TypeScript files into JavaScript.

npm run build-ts

npm run check

Run TypeScript's type checking without emitting compiled files.

npm run check

npm run eslint

Run ESLint on all JavaScript and TypeScript files in the project.

npm run eslint

npm run test

Run Jest for testing with coverage and verbose output.

npm run test

Notes:

  • concurrently: Runs multiple npm commands in parallel.
  • nodemon: Watches for file changes and restarts the server.
  • eslint: Ensures that the code follows the specified coding standards.
  • jest: Runs unit and integration tests.

Contributing

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature/your-feature-name).
  3. Commit your changes (git commit -m 'Add some feature').
  4. Push to the branch (git push origin feature/your-feature-name).
  5. Open a Pull Request.

About

Node Express TypeScript Starter is a boilerplate for building scalable applications with Node.js and Express. It includes essential packages like Axios, Mongoose, JWT, and testing support using Jest and Supertest. The project is also configured with ESLint and Prettier for consistent code quality.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published