How to Write Node.js Applications in Typescript

And make it easier to maintain them while creating fewer bugs

Photo by Joshua Aragon on Unsplash

Package.json

Basic package.json.

The application

Our Node.js application.
{ application: { name: 'node-typescript', version: '0.0.1' } }
{ system: { platform: 'linux', cpus: 8 } }

Webpack

npm i -D webpack webpack-cli

webpack.config.js

Create the ‘webpack.config.js’ file.
Add the start and start:prod scripts on line 8–9.
dist/
main.js
node_modules/
src/
information_logger.js
main.js
package-lock.json
package.json
webpack.config.js

nodemon

npm i -D nodemon-webpack-plugin
Add NodemonPlugin and some necessary changes.
Add build commands and update our start commands.

TypeScript

npm i -D typescript ts-loader @types/node@^10.0.0

ts-loader

Added a rule for ts-loader, added ‘.ts’ to the extensions and changed our entry file to ‘main.ts’.

tsconfig.json

Create a tsconfig.json to tell TypeScript how it should compile the code.

The application

dist/
main.js
node_modules/
src/
information-logger.ts
main.ts
package-lock.json
package.json
tsconfig.json
webpack.config.js

Final note

JavaScript/TypeScript developer at Delen Private Bank.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store