It is recommended to make use of Yarn in place of NPN where possible.
yarn init -y
Install Typescript globally if not already installed, or install on the project using the -D or --save-dev flag
npm install -g typescript
# or make use of: `yarn add -D typescript` or `npm install -D typescript`
yarn add express
- @types/node
- @types/express
- nodemon
- ts-node
yarn add -D @types/express
# @types/node nodemon ts-node
Note: You could install ts-node-dev
in place of nodemon
and ts-node
tsc --init
# or run: `npx tsc --init` if typescript was installed locally in project
{
...
"main": "src/server.ts",
"author": "Edward Oboh",
"license": "MIT",
"scripts": {
"build": "tsc",
"start": "node ./dist/src/server.js",
"start:dev": "nodemon src/server.ts"
}
}
// If making use or `ts-node-dev`, use the following in place of "start:dev":
"start:dev": "ts-node-dev --respawn --clear --transpile-only --ignore-watch node_modules src/server.ts"
{
"compilerOptions": {
"forceConsistentCasingInFileNames": true,
"module": "commonjs",
"esModuleInterop": true,
"outDir": "./dist",
"rootDir": "./src",
"target": "es6",
"skipLibCheck": true,
"strict": true
}
}