Part 1. Project initial setup: TypeScript + Node.js

Node & Yarn installation

$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.36.0/install.sh | bash
# follow the command ouput, restart terminal or source ~/.bashrc
$ nvm install --lts
# Other useful commands:
# check installation: node --version
# to change version: nvm use --lts
# to list installed versions: nvm list
$ curl -o- -L https://yarnpkg.com/install.sh | bash
# restart terminal or source ~/.bashrc

Hello World App with TypeScript

$ mkdir api-example
$ cd api-example
$ yarn init
yarn init v1.22.4
question name (api-example):
question version (1.0.0):
question description: Backend API Example
question entry point (index.js): src/app.ts
question repository url: git@github.com:losikov/api-example.git
question author: Alex Losikov
question license (MIT):
question private:
success Saved package.json
Done in 18.95s.
$ yarn add @types/node typescript 
$ yarn add -D ts-node
$ yarn tsc --init --rootDir src --outDir ./bin --esModuleInterop --lib ES2019 --module commonjs --noImplicitAny true
$ mkdir src
$ echo “console.log(‘Hello World\!\!\!’)” > src/app.ts
$ yarn tsc
$ node ./bin/app.js
Hello World!!!
$ yarn ts-node ./src/app.ts
"scripts": {
"build": "tsc",
"start": "node ./bin/app.js",
"dev": "ts-node ./src/app.ts"
},
$ yarn build
yarn run v1.22.4
$ tsc
Done in 1.10s.
$ yarn start
yarn run v1.22.4
$ node ./bin/app.js
Hello world!!!
Done in 0.08s.
$ yarn dev
yarn run v1.22.4
$ ts-node ./src/app.ts
Hello world!!!
Done in 1.11s.

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