Skip to content

Instantly share code, notes, and snippets.

@vdelacou
Last active July 23, 2023 06:53
Show Gist options
  • Select an option

  • Save vdelacou/996f290aa5d108b55688229e15ff4b3b to your computer and use it in GitHub Desktop.

Select an option

Save vdelacou/996f290aa5d108b55688229e15ff4b3b to your computer and use it in GitHub Desktop.
Start node project
{
"env": {
"node": true,
"es2020": true
},
"extends": [
"plugin:prettier/recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"prettier"
],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"sourceType": "module",
"project": "./tsconfig.json"
},
"plugins": ["@typescript-eslint", "prettier"],
"rules": {}
}

How to install a typescript project

npm init private

curl -o .gitignore https://gist.githubusercontent.com/vdelacou/1954a25d720f702b4af011ba2773001b/raw/.gitignore
curl -o .prettierrc https://gist.githubusercontent.com/vdelacou/58484f1c11af70aaa457f4e5c289e893/raw/.prettierrc
mkdir .vscode
curl -o .vscode/extensions.json https://gist.githubusercontent.com/vdelacou/c5f3fd74c5e836706c0adaeb0d383bd0/raw/extensions.json
curl -o .vscode/settings.json https://gist.githubusercontent.com/vdelacou/c5f3fd74c5e836706c0adaeb0d383bd0/raw/settings.json
curl -o .editorconfig https://gist.githubusercontent.com/vdelacou/58484f1c11af70aaa457f4e5c289e893/raw/.editorconfig
npm install --save-dev typescript ts-node eslint @typescript-eslint/eslint-plugin @typescript-eslint/parser prettier eslint-config-prettier eslint-plugin-prettier
npm install husky --save-dev
npx json -I -f package.json -e 'this.husky={"hooks":{"pre-commit": "npm run lint","pre-push": "npm run lint"}}'
npx json -I -f package.json -e 'this.scripts={...this.scripts , "lint": "eslint . --ext .js,.ts" }'
npx json -I -f package.json -e 'this.scripts={...this.scripts , "start": "ts-node ./src/example.ts" }'
npm install winston
npm install --save-dev @types/node
mkdir src
curl -o src/example.ts https://gist.githubusercontent.com/vdelacou/58484f1c11af70aaa457f4e5c289e893/raw/example.ts
curl -o .eslintrc.json https://gist.githubusercontent.com/vdelacou/58484f1c11af70aaa457f4e5c289e893/raw/.eslintrc.json
curl -o tsconfig.json https://gist.githubusercontent.com/vdelacou/58484f1c11af70aaa457f4e5c289e893/raw/tsconfig.json
import winston from 'winston';
const logger = winston.createLogger({ transports: [new winston.transports.Console()] });
const delay = (milliseconds: number, count: number): Promise<number> => {
return new Promise((resolve) => {
setTimeout(() => {
resolve(count);
}, milliseconds);
});
};
(async () => {
logger.info('Start');
const count = await delay(1000, 2);
logger.info(`End with count: ${count}`);
})().catch((e) => {
logger.error(e);
});
{
"compilerOptions": {
"target": "ES2020",
"module": "commonjs",
"lib": ["ES2020"],
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictBindCallApply": true,
"strictPropertyInitialization": true,
"noImplicitThis": true,
"alwaysStrict": true,
"esModuleInterop": true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment