Create a bare bones node apps using TypeScript.
TypeScript
41
41 commits
updated Dec 7, 2022
Create bare bones NodeJS apps using TypeScript ๐
$ 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.
Write your program using src/index.ts as the entry point, and run it.
$ npm run start
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.
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:
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.
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
$ 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.
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.
If you are using Visual Studio Code you have some things pre-configured under the .vscode folder:
Run tests launch configuration.Launch Program launch configuration.fix lint on save.โโงB.docker-build task.Build and Launch Docker launch configuration.test directory as well.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!
MIT
TypeScript
66.8%
Dockerfile
33.2%
Create a bare bones node apps using TypeScript.
TypeScript
41
41 commits
updated Dec 7, 2022
Create bare bones NodeJS apps using TypeScript ๐
$ 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.
Write your program using src/index.ts as the entry point, and run it.
$ npm run start
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.
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:
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.
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
$ 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.
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.
If you are using Visual Studio Code you have some things pre-configured under the .vscode folder:
Run tests launch configuration.Launch Program launch configuration.fix lint on save.โโงB.docker-build task.Build and Launch Docker launch configuration.test directory as well.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!
MIT
TypeScript
66.8%
Dockerfile
33.2%