/typescript-node-starter

Create a bare bones node apps using TypeScript.

Primary LanguageTypeScriptMIT LicenseMIT

TypeScript Node App Starter All Contributors

Create bare bones NodeJS apps using TypeScript ๐ŸŽ‰

Quick Start:

Clone, cd and Install

$ git clone https://github.com/acamica/typescript-node-starter.git myapp
$ cd myapp
# Install and follow the questions.
$ npm install

โ„น๏ธ Remember to replace myapp with your application name

โ„น๏ธ You can use yarn or npm.

Edit and Run

Write your program using src/index.ts as the entry point, and run it.

$ npm run start

Features

  • ๐Ÿ›ก TypeScript configuration
  • ๐Ÿ›ก Unit testing and tdd/bdd workflow
  • โ˜๏ธ Homogeneous environment using Docker ๐Ÿณ
  • ๐Ÿ‘ฎ TSlint before commit
  • ๐Ÿ‘ฎ Git conventional-changelog messages validation
  • ๐Ÿ” Reliable package management using package.locks
  • ๐ŸŽ‰ Visual Studio Code goodies
  • ๐Ÿ“ Editor config for editors that supports it

๐Ÿ›ก TypeScript Configuration

The project comes with TypeScript v2.3 already configured. You can see and tweak the compiler options with the tsconfig.json file.

By default, the strict master option and noUnusedLocals are enabled, if you are new to typescript you may want to lay back on the strictness by disabling it, and as you get more accustomed you can enable it again.

๐Ÿ‘ฎ Your files should follow the conventions set in tslint.json in order to make a git commit.

๐Ÿ›ก Unit Testing & TDD

Both your code and your test files are in TypeScript. This way if a test fails it's easier to see if its due to a change in the contract or an actual bug.

The project comes with these tools already configured:

  • Mocha: is the test framework that knows how to run your tests.
  • Chai: is an assertion library with different flavours of API.
  • Sinon: is a library that helps spying on functions to see if they where called and how, and creating mocks and stubs for simulating API's.

๐Ÿ‘ฎ All the test need to pass in order to make a git push.

Why mocha + chai + sinon:

  • โœ… It's been proven over and over / Well known in the community.
  • โœ… Decoupled test runner from the assertion and or mock library.
  • ๐Ÿšซ By default it runs all the test sequentially (so it may be slower than others)

How to Use:

Create a test file next to the file you want to test, using the nomenclature <file-name>.test.ts.

You can run your test in a single run by doing:

$ npm t
# or
# npm run test

Or you can enter in a Test Driven Development mode, so whenever you change a file it gets compiled and the test are executed.

$ npm run tdd

๐ŸŒŸ You can install a terminal notifier to receive growl messages with the test execution results.

# How to install growl messages on your platform
# Mac OS X (Darwin):
$ sudo gem install terminal-notifier

# Ubuntu (Linux):
$ sudo apt-get install libnotify-bin

How to Remove:

$ npm remove -D mocha @types/mocha chai @types/chai sinon

In the package.json remove the scripts "test", "watch:test" and "tdd" and if no other script uses it, remove npm-run-all as a dependency.

๐Ÿณ Docker

If the node app you are trying to build is intended to be a service of some sort (micro or monolithic) you may want to guarantee that it runs in reliable environment. Using Docker we can specify the version of os, node and others to reduce the difference between dev, prod and ci environments.

If you want to learn more about Docker you can try this course (in spanish). To remove docker from the project just delete the Dockerfile.

You can build your docker images using the command

$ npm run docker:build

The images created by the build will be tagged with the name and version of your project as specified in the package.json. You can run the image using docker directly or you can run it as an npm script.

$ npm run docker:run

If you need to modify the way your image is built, runned or published, you can edit the docker:* scripts located in the package.json.

Notice that the Dockerfile takes advantage of the layers cache, if you modify the code in the src folder it won't run npm install, it will only build the typescript code. If you change the package.json it will install deps and then build.

๐ŸŽ‰ Visual Studio Code Goodies

If you are using Visual Studio Code you have some things pre-configured under the .vscode folder:

TODO:

  • Add package deps upgrade tool
  • Add automatic Changelog
  • Add automatic semver
  • Add CI
  • Add doc generation
  • Add testing coverage
  • Add readme badges
  • Improve docker integration to build faster
  • Improve tdd watch mode
  • Maybe: Create branch with FRP using rx and ramda
  • Maybe: Create branch with express and knex
  • Maybe: Create branch with CLI using commander or similar
  • Add a gif of growl messages
  • See if we can add a way to create test in a test directory as well.
  • Video of tdd with zen mode
  • add reference for an english course on docker
  • Implement docker:push

Contributors

Thanks goes to these wonderful people (emoji key):


Hernan Rajchert

๐Ÿ’ป ๐Ÿ“– ๐Ÿ›

Facundo Rubin

๐Ÿ’ป ๐Ÿ“– ๐Ÿ›

Cristhian Duran

๐Ÿ›

Nicolรกs Quiroz

๐Ÿ’ป ๐Ÿ“–

Gonzalo Gluzman

๐Ÿ’ป

This project follows the all-contributors specification. Contributions of any kind welcome!

License

MIT