Typescript Node Module Starter Template
Tags: typescript, javascript, nodemodule, template
Published: 2019-11-14 22:46:46

---
title: Typescript Node Module Starter Template
published: true
description: Github template repository for quickly starting new node modules with typescript.
cover_image: https://images.unsplash.com/photo-1566241440091-ec10de8db2e1?ixlib=rb-1.2.1&q=85&fm=jpg&crop=entropy&cs=srgb&dl=luke-chesser-LG8ToawE8WQ-unsplash.jpg
tags: typescript,javascript,node module,template
---
# Archived
This post and accompanying repository have been archived. However, there is a new repository (starter template) which includes [Typescript, Babel, Jest and Rollup configuration.](https://github.com/ivandotv/typescript-babel-jest-rollup)

Github template repository for quickly starting new node modules with typescript.

Are you tired of setting up TypeScript and other dependencies before even writing a single line of code? I am, so I have decided to create a small template repository with some of the tools that I use for everyday development.

You can go check out the repository on [github](https://github.com/ivandotv/node-module-typescript) or continue reading to learn about included tasks, continuous integration, git hooks etc.

## What's Inside

- Typescript is set to `strict` configuration with source map generation.
- ESLint is set up to use [standardJS configuration](https://standardjs.com/index.html#typescript) for typescript, with a few overrides which I think make good common sense. You can see the overrides inside the [.eslintrc.js](.eslintrc.js) file.
- Unit testing is done via [Jest](https://jestjs.io/) in combination with [ts-jest](https://kulshekhar.github.io/ts-jest)
- [Prettier](https://prettier.io/) configuration with a [few custom rules](.prettier.rc).
- Code coverage.

### Tasks

- `prepublishOnly`: run before publishing the module to npm.
- `build`: build typescript.
- `build:watch`: build and watch typescript for changes.
- `test`: run all tests and generate code coverage.
- `test:watch`: run and watch tests for changes (with [typeahead](https://www.npmjs.com/package/jest-watch-typeahead) feature)
- `ci:test` task that is executed by the continuous integration provider (CircleCI) runs tests and uploads code coverage.
- `format`: format all files with [prettier](https://prettier.io) (`tests` and `src` directories).

- `fix:src`: run ESLint on `src` directory with `--fix` flag.
- `fix:tests`: run ESLint on `tests` directory with `--fix` flag.
- `fix`: run `fix:src` and `fix:tests` task in parallel.
- `docs`: generate typescript documentation via [typedoc](https://typedoc.org)

### Continous Integration

[CircleCI](https://circleci.com/) is used for continuous integration. 
Tests are run for node versions 8, 10 and 12.

CircleCI is also set up to upload code coverage to [codecov.io](https://codecov.io) however you can also use [coveralls](https://coveralls.io) for code coverage ( it's currently commented out).

### Git Hooks

There is one git hook setup via [husky](https://www.npmjs.com/package/husky) package in combination with [lint-staged](https://www.npmjs.com/package/lint-staged). Before committing the files all staged files will be run through ESLint and Prettier.

### Debugging

If you are using VS Code as your editor,
there is one debug configuration which is set up to debug currently focused test file inside the editor.

### Typescript Documentation Generator

Typescript documentation is generated via [typedoc](https://typedoc.org).
Currently, it is set up to go into `docs/api` directory and it is generated in markdown so it can be displayed on Github.

- Private members are excluded.
- Only exported properties are documented.

### Conclusion

This repository template has provided me a quick way to start working on a node module with typescript. Feel free to fork the repository and create your version of the template. For example, you can replace [StandardJS](https://standardjs.com/) with [Airbnb](https://github.com/airbnb/javascript) style guide.

I hope you find it useful.