0

What is more resource-efficient: compiling my TypeScript application and running it using Node.js, or running it directly with ts-node (without prior compilation)?

Which approach is more resource-efficient for my scenario: compiling my TypeScript application (I'm using express) and running it with Node.js, or running it directly with ts-node without prior compilation? My application involves connections to both MySQL and S3, and I want to understand which option would consume fewer resources while maintaining optimal performance.

2 Answers2

1

If you are talking about the production scenario, it would be better to build the project (compile it to Javascript) and run the app using the built code.

I am following a similar approach for my dev environment too. I have added a step to build my node express typescript code prior to serving the app from dist/server.js instead of using src/server.ts.

Typescript is a dev dependency and is intended to help developers catch any type errors before deploying it to production. You wouldn't need Typescript in production application. So, it should be better to run your app after building it.

CodeBird
  • 387
  • 1
  • 8
0

I believe your question has already been answered here.

My rule of thumb is combining ts-node with nodemon is great to shorten the feedback loop on your dev environment, but should never be used in production.

As the previous question pointed out, you may run into unsupported features using a dev tool in production and end up spending a lot of time trying to figure it out.

For production always transpile your code either using tsc or some other tool like webpack.