Dependency injection with Dagger 2

Prepare project to use dagger DI in IntelliJ IDE The IntelliJ IDEA Community version 2017.2.5 is used in this example. Open project structure and add dagger as project dependency from Maven repository. com.google.dagger:dagger:2.10 com.google.dagger:dagger-compiler:2.10 The dagger compiler has to be available only for development phase (annotation processing will generate code) so we added it as “Provided” dependency. Enable annotation processing in the project settings and select content root for generated code.

Create an executable JAR from IntelliJ CE

To create executable JAR we need to create new artifact and build it. Build will save everything to the output folder. The version of java used in the article was 1.8. Automatically created build artifact: Open File/Project structure Create new artifact, JAR, from modules with dependencies: Enter proper startup class and select proper function how to use external 3rd party libraries in the target artifact ("copy to the output directory and link via manifest").

Data migrations in Node applications

Setup db-migrate tool As your application grow your database model evolve too. The changes from one version to another is made by migrations. Each migration in the db-migrate tool is in essence a small javascript program. You can code your migration changes manually in the javascript syntax or generate small javascript program (with –sql-file option) to execute your SQL script files. One for the UP and one for the DOWN function of migration.

Testing TypeScript Node app with Jasmine

Setup Jasmine testing framework with Node and TypeScript My typescript project setup is described in this article. To be able to write tests in typescript with Jasmine framework we need to setup project environment with some Jasmine specifics. This scaffold project is also available on the github. Initialize typescript compiler and linter : npm install typescript@latest –save-dev tsc –init –moduleResolution node –target ES2017 –sourceMap –module commonjs –removeComments –outDir dist npm install tslint –save-dev tslint –init

Create a Node cluster with Koa and TypeScript

Cluster Any JavaScript program runs in single OS process but of course is able to process requests asynchronously. On the Node server we are able to start multiple processes. To do that we use cluster module, so you are not really limited to one CPU core anymore. Before start you need to install project prerequisites: npm install koa @types/koa koa-router @types/koa-router node-fetch @types/node-fetch –save If you need help with basic project setup look at this blog article where I describe basic setup steps.

Asynchronous programming with async/await pattern

JavaScript is single threaded Everything running in JavaScript is running in the single OS process and consume a single thread. But when you are waiting for something outside the JavaScript process to happen, like waiting for database query to be executed or some file stream reader to load a file, you are able to return control back to your main JavaScript event loop and therefore any new event/request in your JavaScript program will be processed in the meantime.