1

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 1

1

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!'));
Sign up to request clarification or add additional context in comments.

4 Comments

TypeError: routes\index.js: Emit skipped getting this error
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 kindly accept it by clicking the check icon beside the answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.