Personal Setup TypeScript + Node.js Project
ukkoon
Posted on June 27, 2022
1. install Node.js
install nvm using homebrew
brew install nvm
# do additional setup for nvm
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
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
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
tsconfig.json
{
"compilerOptions": {
"target": "es2016",
"module": "commonjs",
"rootDir": "./src",
"outDir": "./dist",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
}
}
package.json
"scripts": {
"dev": "ts-node-dev src/index.ts",
"build": "tsc",
"start": "node dist/index.js"
}
connect to github repository
setup for service
💖 💪 🙅 🚩
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.