I Want to develop node js express application with typescript. To integrate typescript in node js I followed a few tutorials from online and it is working as expected. but .ts files converted .js and it is stored in dist folder but I don't want like that. can I run my project with only with .ts files instead of converting to .js files in dist folder?
1 Answer
Yes, have a look at ts-node
Install it globally:
npm install -g ts-node
Run app.ts:
ts-node app.ts
Answering your question in comments:
First run tsc --init to create tsconfig.json automatically.
Then install npm i @types/node and npm i @types/express
In ./routes/index.ts:
import {Request, Response} from 'express'
export function Hello(req: Request ,res: Response) {
res.send('Hello World')
}
In app.ts
import express from 'express';
const app = express();
import {Hello} from './routes/index'
app.get('/', Hello);
app.listen(3000, () => console.log('Example app listening on port 3000!'));
4 Comments
Rajesh Yadav
TypeError: routes\index.js: Emit skipped getting this error
Rajesh Yadav
import express from 'express'; const app = express(); import indexRouter from './routes/index' app.get('/', indexRouter); app.listen(3000, () => console.log('Example app listening on port 3000!'));
@RajeshYadav see meta.stackexchange.com/questions/5234/…