generator-nts

A minimal Yeoman Generator for creating NodeJS modules using TypeScript and including a minimal express server.

Usage no npm install needed!

<script type="module">
  import generatorNts from 'https://cdn.skypack.dev/generator-nts';
</script>

README

TypeScript NodeJS Generator

Build Status npm version

This is a fork of this generator but I added express to it.

I'm a minimal Yeoman generator for creating NodeJS express servers using TypeScript. I let you quickly setup a project with latest available tools and best practices.

I use:

  • npm - as task runner. You can choose to use gulp instead.
  • mocha - as testing framework to write specs in TypeScript itself.
  • istanbul - a JavaScript code coverage tool working on TypeScript files.

I don't use: a UI renderer or anything visual I am a pure API targeted generator. So with me, you should build REST API's.

You want to know if you can change any of these? Of course, why not? It is your module after all. I simply get down to business of generating, no questions asked. Once done, I get out of the way and you can do as you please!

Usage

Install generator-nts globally. If you are planning to use gulp, install gulp-cli globally.

$npm install -g generator-nts

Create a new directory and cd into it.

$mkdir my-new-project && cd $_

Run the generator.

$yo nts

Run npm run for information on available tasks.

 $npm run
Lifecycle scripts included in node-ts:
  test
    npm run build && mocha --compilers ts:ts-node/register --recursive test/**/*-spec.ts
  coverage
    nyc --reporter=text --reporter=html mocha --compilers ts:ts-node/register

available via `npm run-script`:
  clean
    rimraf lib
  lint
    tslint --format verbose 'src/**/*.ts'
  build
    npm run clean && npm run lint && echo Using TypeScript && tsc --version && tsc --pretty
  coverage
    nyc --reporter=text --reporter=html mocha --compilers ts:ts-node/register
  watch
    npm run build -- --watch
  watch:test
    npm run test -- --watch

Highlights of the latest release

  • I use latest version of TypeScript.
  • I use npm to fetch type definitions making life so much easier. You can find more information on https://blogs.msdn.microsoft.com/typescript/2016/06/15/the-future-of-declaration-files/.
  • I use mocha as testing framework as it allows easier test runs from command line. Also, one of the most important things regarding testing is now you can write tests in TypeScript itself. The out-of-box configuration includes use of ts-node as mocha compiler allowing executing specs written in TypeScript without compiling them first.
  • I need no global dependencies. Every dependency such as TypeScript and tslint is installed as local dev dependency allowing you to freely use different versions of these for different modules.
  • I provide test coverage support using istanbul.
  • I provide nice integration with VS Code editor. I configure build, clean, coverage and test tasks that you can run using Run Task option.

License

MIT