Convert Figma logo to code with AI

jsynowiec logonode-typescript-boilerplate

Minimalistic project template to jump start a Node.js back-end application in TypeScript. ESLint, Jest and type definitions included.

2,704
538
2,704
3

Top Related Projects

A reference example for TypeScript and Node with a detailed README describing how to use the two together.

12,836

TypeScript execution and REPL for node.js

Starter kit with zero-config for building a library in TypeScript, featuring RollupJS, Jest, Prettier, TSLint, Semantic Release, and more!

The most basic TypeScript starter I could think of

A delightful way to building a RESTful API with NodeJs & TypeScript by @w3tecch

Quick Overview

The jsynowiec/node-typescript-boilerplate is a minimalist, ready-to-use template for building Node.js projects with TypeScript. It provides a solid foundation for developing scalable and maintainable applications, including essential tools for testing, linting, and formatting.

Pros

  • Pre-configured with TypeScript, Jest, ESLint, and Prettier for immediate development
  • Includes GitHub Actions for automated testing and CI/CD
  • Supports both CommonJS and ES modules
  • Regularly updated to maintain compatibility with the latest Node.js LTS versions

Cons

  • May include more tools than needed for very simple projects
  • Requires familiarity with TypeScript and Node.js ecosystem
  • Limited customization options out of the box
  • May need additional configuration for complex project structures

Getting Started

  1. Clone the repository:

    git clone https://github.com/jsynowiec/node-typescript-boilerplate.git my-project
    cd my-project
    
  2. Install dependencies:

    npm install
    
  3. Start development:

    npm run start:dev
    
  4. Build and run the project:

    npm run build
    npm run start
    
  5. Run tests:

    npm test
    

These instructions will set up the boilerplate and allow you to start developing your Node.js TypeScript project immediately.

Competitor Comparisons

A reference example for TypeScript and Node with a detailed README describing how to use the two together.

Pros of TypeScript-Node-Starter

  • More comprehensive setup with Express.js, MongoDB, and authentication
  • Includes detailed documentation and explanations for each feature
  • Offers a production-ready structure with MVC pattern implementation

Cons of TypeScript-Node-Starter

  • Potentially overwhelming for beginners due to its complexity
  • Might include unnecessary features for simpler projects
  • Less frequently updated compared to node-typescript-boilerplate

Code Comparison

TypeScript-Node-Starter:

import express from "express";
import compression from "compression";
import session from "express-session";
import bodyParser from "body-parser";
import lusca from "lusca";

node-typescript-boilerplate:

import { add } from './main';

describe('add', () => {
  it('adds two numbers', () => {
    expect(add(1, 2)).toBe(3);
  });
});

The TypeScript-Node-Starter example shows the setup for an Express.js application with various middleware, while the node-typescript-boilerplate example demonstrates a simple test setup using Jest.

TypeScript-Node-Starter is better suited for full-stack applications with a more complex structure, while node-typescript-boilerplate provides a minimal setup ideal for smaller projects or as a starting point for custom configurations.

12,836

TypeScript execution and REPL for node.js

Pros of ts-node

  • Directly executes TypeScript files without separate compilation step
  • Supports REPL for interactive TypeScript execution
  • Integrates seamlessly with Node.js ecosystem and tools

Cons of ts-node

  • May have slower startup time for large projects
  • Limited customization options for TypeScript compilation process
  • Potential performance overhead in production environments

Code Comparison

ts-node:

// Execute TypeScript directly
import { sum } from './math';
console.log(sum(5, 3));

node-typescript-boilerplate:

// Compile TypeScript to JavaScript first
"scripts": {
  "build": "tsc",
  "start": "node build/index.js"
}

Summary

ts-node offers a more streamlined development experience with direct TypeScript execution and REPL support, making it ideal for quick prototyping and smaller projects. node-typescript-boilerplate provides a more structured setup with separate build and run steps, which can be beneficial for larger projects and production deployments. The choice between the two depends on project requirements, team preferences, and performance considerations.

Starter kit with zero-config for building a library in TypeScript, featuring RollupJS, Jest, Prettier, TSLint, Semantic Release, and more!

Pros of typescript-library-starter

  • More comprehensive tooling setup, including automatic documentation generation with TypeDoc
  • Includes semantic-release for automated versioning and publishing
  • Provides a more opinionated structure for library development

Cons of typescript-library-starter

  • May be overly complex for simpler projects or beginners
  • Less frequently updated compared to node-typescript-boilerplate
  • Some included tools might not be necessary for every project

Code Comparison

node-typescript-boilerplate:

{
  "scripts": {
    "start": "node build/src/main.js",
    "clean": "rimraf coverage build tmp",
    "build": "tsc -p tsconfig.json",
    "build:watch": "tsc -w -p tsconfig.json",
    "lint": "eslint . --ext .ts,.tsx"
  }
}

typescript-library-starter:

{
  "scripts": {
    "lint": "tslint  --project tsconfig.json -t codeFrame 'src/**/*.ts' 'test/**/*.ts'",
    "prebuild": "rimraf dist",
    "build": "tsc --module commonjs && rollup -c rollup.config.ts && typedoc --out docs --target es6 --theme minimal --mode file src",
    "start": "rollup -c rollup.config.ts -w",
    "test": "jest --coverage",
    "test:watch": "jest --coverage --watch"
  }
}

The code comparison shows that typescript-library-starter includes more advanced build and test configurations, while node-typescript-boilerplate keeps it simpler with basic TypeScript compilation and linting.

The most basic TypeScript starter I could think of

Pros of simple-typescript-starter

  • Simpler setup with fewer dependencies, making it easier for beginners to understand and use
  • Includes a basic Express server setup, which is useful for web application development
  • Uses ts-node-dev for faster development and automatic restarting

Cons of simple-typescript-starter

  • Less comprehensive testing setup compared to node-typescript-boilerplate
  • Fewer pre-configured tools and scripts for code quality and formatting
  • Less frequent updates and maintenance compared to node-typescript-boilerplate

Code Comparison

simple-typescript-starter (package.json):

"scripts": {
  "start": "npm run build && node build/index.js",
  "start:dev": "ts-node-dev --respawn --transpile-only src/index.ts",
  "build": "tsc"
}

node-typescript-boilerplate (package.json):

"scripts": {
  "start": "node build/src/main.js",
  "clean": "rimraf coverage build tmp",
  "build": "tsc -p tsconfig.json",
  "build:watch": "tsc -w -p tsconfig.json"
}

The simple-typescript-starter uses ts-node-dev for development, while node-typescript-boilerplate relies on TypeScript's watch mode. The node-typescript-boilerplate also includes a clean script for removing build artifacts.

Both projects provide a solid foundation for TypeScript development, with node-typescript-boilerplate offering a more comprehensive setup and simple-typescript-starter focusing on simplicity and ease of use for beginners.

A delightful way to building a RESTful API with NodeJs & TypeScript by @w3tecch

Pros of express-typescript-boilerplate

  • Includes Express.js framework, providing a robust foundation for web applications
  • Offers more comprehensive features like database integration, authentication, and API documentation
  • Provides a scalable project structure suitable for larger applications

Cons of express-typescript-boilerplate

  • More complex setup and steeper learning curve due to additional features
  • Potentially overkill for simple projects or microservices
  • Less frequently updated compared to node-typescript-boilerplate

Code Comparison

node-typescript-boilerplate:

import { hello } from './main';

console.log(hello());

express-typescript-boilerplate:

import { Container } from 'typedi';
import { UserService } from './services/UserService';

const userService = Container.get(UserService);
const users = await userService.find();

The code snippets highlight the difference in complexity and features between the two boilerplates. node-typescript-boilerplate focuses on a simple TypeScript setup, while express-typescript-boilerplate demonstrates dependency injection and service-based architecture.

Both boilerplates offer valuable starting points for TypeScript projects, with node-typescript-boilerplate being more suitable for lightweight applications and express-typescript-boilerplate providing a comprehensive foundation for full-fledged web applications.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

node-typescript-boilerplate

Sponsor TypeScript version Node.js version APLv2 Build Status - GitHub Actions

👩🏻‍💻 Developer Ready: A comprehensive template. Works out of the box for most Node.js projects.

🏃🏽 Instant Value: All basic tools included and configured:

  • TypeScript 5.4
  • ESM
  • ESLint with some initial rules recommendation
  • Jest for fast unit testing and code coverage
  • Type definitions for Node.js and Jest
  • Prettier to enforce consistent code style
  • NPM scripts for common operations
  • EditorConfig for consistent coding style
  • Reproducible environments thanks to Volta
  • Example configuration for GitHub Actions
  • Simple example of TypeScript code and unit test

🤲 Free as in speech: available under the APLv2 license.

Getting Started

This project is intended to be used with the latest Active LTS release of Node.js.

Use as a repository template

To start, just click the Use template link (or the green button). Start adding your code in the src and unit tests in the __tests__ directories.

Clone repository

To clone the repository, use the following commands:

git clone https://github.com/jsynowiec/node-typescript-boilerplate
cd node-typescript-boilerplate
npm install

Download latest release

Download and unzip the current main branch or one of the tags:

wget https://github.com/jsynowiec/node-typescript-boilerplate/archive/main.zip -O node-typescript-boilerplate.zip
unzip node-typescript-boilerplate.zip && rm node-typescript-boilerplate.zip

Available Scripts

  • clean - remove coverage data, Jest cache and transpiled files,
  • prebuild - lint source files and tests before building,
  • build - transpile TypeScript to ES6,
  • build:watch - interactive watch mode to automatically transpile source files,
  • lint - lint source files and tests,
  • prettier - reformat files,
  • test - run tests,
  • test:watch - interactive watch mode to automatically re-run tests

Additional Information

Why include Volta

Volta’s toolchain always keeps track of where you are, it makes sure the tools you use always respect the settings of the project you’re working on. This means you don’t have to worry about changing the state of your installed software when switching between projects. For example, it's used by engineers at LinkedIn to standardize tools and have reproducible development environments.

I recommend to install Volta and use it to manage your project's toolchain.

ES Modules

This template uses native ESM. Make sure to read this, and this first.

If your project requires CommonJS, you will have to convert to ESM.

Please do not open issues for questions regarding CommonJS or ESM on this repo.

Backers & Sponsors

Support this project by becoming a sponsor.

License

Licensed under the APLv2. See the LICENSE file for details.