Skip to content
Maxi Montenegro edited this page May 12, 2022 · 14 revisions

I'm going to use this wiki page to document all the necesary steps to reproduce this project ๐Ÿ˜€

Express ๐Ÿค™

Install express and its types:

npm install express
npm install --save @types/express

Typescript ๐Ÿ˜Ž

Install typescript and its types:

npm i -D typescript @types/express @types/node

Linter ๐Ÿ™‡โ€โ™‚๏ธ

Install eslint with typescript dependencies:

sudo npm install -g eslint
npm i -D typescript @typescript-eslint/parser @typescript-eslint/eslint-plugin

Create .eslintrc file in the root of your project and paste this code inside:

{
  "parser": "@typescript-eslint/parser",
  "plugins": ["@typescript-eslint"],
  "rules": {
    "semi": ["error", "always"],
    "quotes": [2, "single"]
  }
}

Install this VSCode extension to teach it to understand eslint.

And last but not least, paste this code to VSCode settings.json

{
  "eslint.validate": ["typescript"]
}

Lint all files with:

 eslint --ext ts .

Database Connection ๐Ÿ”Œ

Install mongoose:

npm install mongoose
npm install @types/mongoose --save-dev

Cors ๐Ÿ‘ฎ

Install cors:

npm install cors
npm i --save-dev @types/cors

And modify the index.ts to include the following sentences

import cors from 'cors';
app.use(express.json());
app.use(cors());

Dependency Injection ๐Ÿ’‰

Install tsyringe

npm install --save tsyringe

And modify the tsconfig.json to include the following settings

{
  "compilerOptions": {
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true
  }
}

Test ๐Ÿงช

Install jest

npm install --save-dev jest ts-jest @types/jest

Generate config file for ts-jest

npx ts-jest config:init

Create a script in package.json

{
    test: "jest"
}

What should do I put here? ๐Ÿ™ƒ

For any question meet me at Wir Konnen ๐Ÿป

Clone this wiki locally