Personal Setup TypeScript + Node.js Project

ukkoon

ukkoon

Posted on June 27, 2022

Personal Setup TypeScript + Node.js Project

1. install Node.js

install nvm using homebrew

brew install nvm
# do additional setup for nvm
Enter fullscreen mode Exit fullscreen mode

install Node.js using nvm

# install specific version of Node.js
nvm install v16.15.1
nvm install v12.13.0

# show list of Node.js version
nvm ls

# use specific version of Node.js
nvm use 12.13.1
nvm use 16.15.1
Enter fullscreen mode Exit fullscreen mode

2. init Node.js project

# create folder, npm init by default setting 
mkdir sample_project && cd "$_" && npm init --y

# install required basic package for development
npm i -D typescript @types/node ts-node-dev 
Enter fullscreen mode Exit fullscreen mode

typescript, their type definition is placed at node_modules/@types
@types/node this packages contains type definition for Node.js (e.g. Promise)
ts-node TypeScript execution and REPL for Node.js
ts-node-dev Tweaked version of node-dev that uses ts-node under the hood.

3. additional setup

generate tsconfig.json file

npx tsc --init
Enter fullscreen mode Exit fullscreen mode

tsconfig.json

{
  "compilerOptions": {
    "target": "es2016",
    "module": "commonjs",
    "rootDir": "./src",
    "outDir": "./dist",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": true
  }
}
Enter fullscreen mode Exit fullscreen mode

package.json

 "scripts": {
    "dev": "ts-node-dev src/index.ts",
    "build": "tsc",
    "start": "node dist/index.js"
  }
Enter fullscreen mode Exit fullscreen mode

connect to github repository

setup for service

💖 💪 🙅 🚩
ukkoon
ukkoon

Posted on June 27, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related