01 Setup - jp7io/typescript-crud-api GitHub Wiki
Setup
Create new directory for the project and enter into it
mkdir typescript-crud-api
cd typescript-crud-api
Git
git init -b main
code .gitignore
node_modules/
build/
.env
Initialize node
yarn init --yes
Add TypeScript
yarn add typescript
code tsconfig.json
{
"compilerOptions": {
"lib": ["es5", "es6", "dom"],
"target": "es6",
"module": "commonjs",
"moduleResolution": "node",
"outDir": "./build",
"rootDir": "./src",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"esModuleInterop": true,
"resolveJsonModule": true
}
}
Create application root file
mkdir ./src
code ./src/index.ts
console.log('Application is up and running!');
Add nodemon and concurrently to automate (re)building at development
yarn add nodemon concurrently
code package.json
...
"license": ...,
"scripts": {
"dev": "concurrently npm:start:*",
"start:build": "tsc -w",
"start:server": "nodemon ./build/index.js",
"start": "node ./build/index.js",
"build": "tsc",
"test": "echo \"Error: no test specified\" && exit 1"
},
...
yarn dev
We should see "Application is up and running!" on terminal output (maybe a restart will be required for the first run).
Commit
git add .
git commit -m "Setup"