Guide available in Spanish
- pnpm to manage dependencies
- TypeScript
- ESlint for syntax errors
- Prettier to format the code
- Create a directory for the project
mkdir node_project
cd node_project- Initialize the project with pnpm
pnpm initCopy the following and paste it into package.json.
{
"name": "node_project",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "tsc && node dist/index.js",
"lint": "eslint .",
"format": "pnpm exec prettier . --write",
"format-spec": "prettier --write",
"check": "pnpm exec prettier . --check",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@eslint/js": "^9.9.1",
"eslint": "^9.9.1",
"globals": "^15.9.0",
"prettier": "3.3.3",
"typescript": "^5.5.4",
"typescript-eslint": "^8.3.0"
}
}- Create a configuration file for TypeScript
touch tsconfig.jsonCopy the following and paste it into tsconfig.json.
{
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"target": "es6",
"moduleResolution": "node",
"sourceMap": true,
"outDir": "dist",
"strict": true,
"noImplicitAny": true,
"skipLibCheck": true
},
"lib": ["es2015"],
"include": ["**/*"],
"exclude": ["node_modules", "dist"]
}- Install eslint
pnpm install --save-dev eslintInitialize eslint
pnpm eslint --initCopy the following and paste it into eslint.config.mjs.
import globals from 'globals';
import pluginJs from '@eslint/js';
import tseslint from 'typescript-eslint';
export default [
{ files: ['**/*.{js,mjs,cjs,ts}'] },
{ ignores: ['node_modules', 'dist'] },
{ languageOptions: { globals: globals.node } },
pluginJs.configs.recommended,
...tseslint.configs.recommended,
];- Install prettier
pnpm install --save-dev prettierCreate a configuration file for prettier
touch .prettierrcCopy the following and paste it into .prettierrc.
{
"printWidth": 80,
"tabWidth": 4,
"useTabs": false,
"semi": true,
"singleQuote": true,
"trailingComma": "es5",
"bracketSpacing": true,
"jsxBracketSameLine": false,
"arrowParens": "always"
}Create an ignore file for Prettier
touch .prettierignoreCopy the following and paste it into .prettierignore.
node_modules
distPrettier will also follow rules specified in .gitignore if it exists in the same directory from which it is executed.
pnpm lintFormat the code
pnpm formatFormat the specific folder or file
pnpm format-spec <path>Format the specific test file
pnpm format-spec <ruta/**/*.test.js>Check if the code is formatted correctly
pnpm checkPrerequisites:
- Have a
src/index.ts, etc.- Install the dependencies
pnpm startCompiles the project and runs the file
dist/index.js
Made with 👐 by Rapax
Tips are welcome through Lightning Zap to ⚡rapax@lawallet.ar.