Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it a bad practise to use ts-node in production?

Tags:

I'm currently using ts-node with express in production and it's working well so far. Is there any reason that I should compile and run .js instead?

like image 901
Elect2 Avatar asked Mar 07 '20 19:03

Elect2


People also ask

What is ts-node for?

ts-node is a TypeScript execution engine and REPL for Node. js. It JIT transforms TypeScript into JavaScript, enabling you to directly execute TypeScript on Node. js without precompiling.

What does ts-node Transpile only do?

ts-node offers the -transpile-only or -T flag to compile your TypeScript code into JavaScript.


1 Answers

According to Blake Embrey, the author of ts-node, you can use it in production BUT you should use it with the --transpile-only flag.

Example:

ts-node --transpile-only ./src/start.ts 

If you are compiling with transpile only, it will have a lower memory footprint as no type information will be generated. However, it can come to problems when you are using reflect-metadata (with experimental support for decorators).

In short: Use ts-node --transpile-only (there is also ts-node-transpile-only) in production when you are not using reflect-metadata. Otherwise, use tsc in combination with classic node.

like image 73
Benny Neugebauer Avatar answered Oct 05 '22 07:10

Benny Neugebauer