Difference between `tsc` and `ts-node` on production builds
Table of Contents
Summary #
While running a server on production, there are two options, tsc
and ts-node
. This article will explain the difference between these two options and when to use each one.
tsc
is used to transpile TypeScript code to JavaScript code, and then run the JavaScript code with Node.js.ts-node
is used to run TypeScript code directly without transpiling it first.
Details #
tsc #
To transpile the TypeScript code to JavaScript first, before running it with Node.js, may have a slightly longer startup time because the transpilation step is an additional step in the process. However, once the server runs, there would be no significant performance differences between the transpiled JavaScript code and the original TypeScript code.
ts-node #
To run the TypeScript code directly without transpiling it first may have slightly better performance in startup time, as there is no transpilation step. However, this comes at the cost of a slight overhead caused by ts-node interpreting the TypeScript code at runtime.
Conclusion #
Overall, the performance difference between these two options is negligible for most use cases, and the choice should be based on developer preference and development flow. However, I think it’s better to test and profile the application using both options to decide which is better for large and performance-sensitive applications.