Node.js and Typescript
tsc --init
npm init
npm install --save express
npm install --save body-parser
npm install --save-dev ts-node-dev
npm install --save-dev typescript
npm install --save-dev @types/node
npm install --save-dev @types/express
npm install --save-dev @types/body-parser
tsconfig.json
...
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"moduleResolution": "node", //allows us to use new import of modules
...
"outDir": "./dist", //here will be generated javascript files
"rootDir": "./src", //here will be our typescript files
...
}
...
package.json
...
"scripts": {
"start": "ts-node-dev src/index.ts", //here will be generated javascript files
...
}
...
Now you can use npm start
and code will be automatically converted from typescript to javascript during development.