npm start
- Init project
npm init -y
- Install ts locally
npm install typescript --save-dev
- Make source folder
mkdir src
- Add script
Add this script to package.json:
"tsc": "tsc",
- Initialize tsc (gen tsconfig.json)
npm run tsc -- --init
- Edit tsconfig.json (uncomment and update values and save):
"compilerOptions": {
"target": "ES6",
"module": "CommonJS",
"rootDir": "./src",
"outDir": "./dist",
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules"]
- create a file
touch src/app.ts
- update main in package.json
"main": "./dist/app.js",
- add build script command
"build": "tsc",
- run build
npm run build
ls -ls dist
cat dist/app.js
- add a start script command and save the file
"start": "node dist/app.js",
- run the start script
npm start
- add a prestart script command to build first
"scripts": {
"prestart": "npm run build",
- add a clean command:
"clean": "rm -rf dist",
- run the clean command
npm run clean
-
Copy the .gitignore file from here:
-
https://github.com/microsoft/TypeScript-Node-Starter/blob/master/.gitignore