Skip to content

Instantly share code, notes, and snippets.

@Klerith
Last active July 22, 2024 00:19
Show Gist options
  • Save Klerith/3ba17e86dc4fabd8301a59699b9ffc0b to your computer and use it in GitHub Desktop.
Save Klerith/3ba17e86dc4fabd8301a59699b9ffc0b to your computer and use it in GitHub Desktop.
Node con TypeScript - TS-Node-dev simplificado

Node con TypeScript - TS-Node-dev (preferido)

  1. Instalar TypeScript y demás dependencias
npm i -D typescript @types/node ts-node-dev rimraf
  1. Inicializar el archivo de configuración de TypeScript ( Se puede configurar al gusto)
npx tsc --init --outDir dist/ --rootDir src
  1. Crear scripts para dev, build y start (Más sobre TS-Node-dev aquí)
  "dev": "tsnd --respawn --clear src/app.ts",
  "build": "rimraf ./dist && tsc",
  "start": "npm run build && node dist/app.js"
@codeConqueror7
Copy link

Un saludo Fernando

@ariasortez
Copy link

Si agregan la siguiente linea al package.json pueden acceder a las variables de entorno nativamente:

--env-file=.env

Node ya permite el acceso de manera nativa por si a alguien le sirve.

"scripts": { "dev": "tsnd --respawn --clear --env-file=.env src/app.ts", "build": "rimraf ./dist && tsc", "start": "npm run build && node dist/app.js" },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment