express.ts code example
Example 1: add typescript in node
npm init-y
yarn add -D @types/node typescript ts-node
npx tsconfig.json
"start": "ts-node src/index.ts",
console.log("Hello TypeScript");
yarn start
Example 2: express ts
import express = require('express');
const app: express.Application = express();
app.get('/', function (req, res) {
res.send('Hello World!');
});
app.listen(3000, function () {
console.log('Example app listening on port 3000!');
});
Example 3: typescript tutorial nodejs
npm install express @types/express
Example 4: express typescript
try this config for nodejs + typescript using babel
https://pastebin.com/TR4BXPqL