NATSUHIKO.JPhome

NodeTS snippets to copy & paste

Useful snippets to initialize Typescript Node projects.

Next React

install.sh

npm install --save react react-dom next typescript @types/react @types/react-dom @types/node

TypeScript Node Core + Hot Reload

install.sh

npm install --save ts-node typescript @types/node ts-node-dev

package.json

... "start": "ts-node-dev --respawn --watch main main/index.ts" ...

tsconfig.json

{ "compilerOptions": { "target": "es6", "outDir": ".dist", "sourceMap": true, "module": "commonjs", "strict": true, "moduleResolution": "node", "removeComments": true, "emitDecoratorMetadata": true, "esModuleInterop": false, "experimentalDecorators": true, "forceConsistentCasingInFileNames": true } }

express

install.sh

@types/express express # websocket @types/express-ws express-ws # typeorm mysql typeorm reflect-metadata typeorm-routing-controllers-extensions routing-controllers

prettier

install.sh

prettier husky lint-staged

package.json

... "husky": { "hooks": { "pre-commit": "lint-staged" } }, "lint-staged": { "*.{ts,tsx}": [ "prettier --write" ] }, ...

prettier.config.js

module.exports = { trailingComma: 'es5', singleQuote: true, jsxSingleQuote: false, printWidth: 100, }

jest

install.sh

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

package.json

... "test": "jest --runInBand --silent=false --verbose false" ...

jest.config.js

module.exports = { "moduleFileExtensions": ["ts", "tsx", "js"], "transform": { "^.+\\.ts$": "ts-jest" }, "globals": { "ts-jest": { "tsConfig": "tsconfig.server.json" } }, "testMatch": [ "**/tests/**/*.test.ts" ] };