-
Crear al package.json
npm init -y
-
Instalar typescript
npm i typescript -D
-
instalar compilador TS
npx tsc --init
-
configurar tsconfig.json
descomentar estas lineas
"baseUrl": "./src", "outDir": "./build", "allowSyntheticDefaultImports": true,
-
Creamos nuestra carpeta src
dentro de esa carpeta creamos el index.ts y de ejemplo creamos una función suma.
const add = (a:number,b:number)=>{ return a+b; } console.log(add(2,3));
Ejecutamos el programa
npx tsc src/index.ts
-
Agregando script para ejecutar en el archivo package.json
"scripts": { "test": "echo \"Error: no test specified\" && exit 1", "start": "tsc src/index.ts" },
Ahora solo ejecutamos
npm start
instalamos ts-node
npm i ts-node
instalamos express y sus tipos
npm i express
npm i --save-dev @types/express
instalamos para que el servidor actualize solo
npm i ts-node-dev
-
cambiando la configuración en el archivo package.json
"scripts": { "test": "echo \"Error: no test specified\" && exit 1", "start": "ts-node-dev src/index.ts" },
-
Creando el servidor en el archivo index.ts
import express, { Request, Response } from 'express'; const app=express(); app.get('/', (req:Request, res:Response)=>{ res.status(200).send('Hola este es mi server') }); app.listen(3000, ()=>console.log('Server started'));

Build apps, not infrastructure.
Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (0)