Node-Typescript-Boilerplate

Dec 28, 2023 | Programming

Skeleton for Node.js applications written in TypeScript

Purpose

The main purpose of this Skeleton is to quickly and efficiently set up a server application using Node.js and TypeScript. It’s perfect for those looking to dive into development without any unnecessary hassle!

Common Features

  • Quick start with simple scaffolding based on TypeScript syntax
  • Easy global environment configuration and error handling
  • Flexible for adding new features
  • Continuous Integration with integrated tools
  • Comprehensive documentation standards with Swagger support
  • Solid test coverage with ESLint, Prettier, and Husky integration
  • Production-ready setup with security best practices

Core NPM Modules

  • express, @types/express
  • @types/node
  • typescript
  • dotenv
  • cors
  • helmet
  • http-status-codes
  • winston

Getting Started

Start The Application in Development Mode

  • Clone the Application:
    git clone https://github.com/santoshshinde2012/node-boilerplate.git
  • Install the dependencies:
    npm install
  • Start the application:
    npm run dev

Start The Application in Production Mode

  • Install the dependencies:
    npm install
  • Create the build:
    npm run build
  • Start the application:
    npm run start
  • Check the .env values before you start the application by consulting your .env.example file.

Understanding The Code – An Analogy

Think of setting up your Node.js application with TypeScript like building a new Lego model. Each component (like express, helmet, etc.) is a unique Lego block that contributes to the final structure. When you clone the repository, you’re gathering all the pieces. Running npm install is like sorting out the blocks to ensure you have everything you need at the start. The build command compiles your created structure, while starting your server initiates the operation—like displaying your completed Lego model proudly on a shelf!

Project Structure

The project contains various organized folders, each serving a specific purpose:

  • wiki: Documentation and instruction files
  • src: Contains source files
  • src/abstractions: Abstract classes and interfaces
  • src/components: REST API components, including controllers
  • src/lib: Reusable utilities and logger source code
  • src/middleware: Express middlewares
  • build: Compiled source files
  • tests: Includes all test cases

Swagger API Documentation

The Swagger documentation can be accessed at: http://localhost:8080/docs

Common Troubleshooting

  • My git pre-commit hook is not executable by default: Run the commands to make them executable:
    chmod ug+x .husky/*
    chmod ug+x .githooks/*
  • Is your application not starting as expected? Double-check that you’ve installed the necessary dependencies and are in the correct directory.
  • For unresolved errors, reference the .env.example for required environment variables.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

Conclusion

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox