TypeStrong / ts-node

TypeScript execution and REPL for node.js

Home Page:https://typestrong.org/ts-node

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Should I use it in production?

aayushkapoor206 opened this issue · comments

I couldn't find any mention about it in the readme

No, not really. In production you'd want to only be in transpile mode (you should have already type checked). If someone wants to contribute some PRs for this functionality, we can get it in. Otherwise I'd wait for #44.

So @blakeembrey, can we now use it in production? As in

$ ts-node -F server.ts

I currently do tsc && node build/server.js, but the very succinctness and beauty of the above is totally worth it if I'll get no significant overheads over the second option.

Definitely your choice, go ahead 😄 There's no heavy overheads.

using ts-node -F . to run ts code missing metadata. reflect-metadata can't get field's type.

tsc && node . is OK

That make sense to me. Fast mode isn’t using type information, it’s just plain transpiling files on the fly. That’s not equivalent to tsc. Use the regular mode that is if you want type information. It’s a good point though and I can document that.

So, should I use in production?
ts-node . or tsc && node .

That's not something I can tell you. I can tell you that loading type information has a larger overhead, but it shouldn't impact performance (only memory once started).

Hey, FYI there still no documentation mention about the --fast or -F option. I just found it here. That's something worth adding to the readme along with a basic intro about what it does, if its still a valid option. I saw somewhere that it's enabled by default, is that true?

commented

The release note mentions use --type-check for type checking behaviour, but its not mentioned again in the docs?

That’s because it was three major releases ago and the behaviour was reverted. It confused other people to not type check by default.

So the --transpileOnly works similar to previous --fast?

The same, yes.

So the --transpileOnly works similar to previous --fast?

Except its --transpile-only or -T

So, the summary of this thread is that "If i use ts-node server.ts in production, that is completely okay, as it is transpile only mode by default so dont need to pass --fast or --transpile-only flags.

correct me if something is missed.

So, the summary of this thread is that "If i use ts-node server.ts in production, that is completely okay, as it is transpile only mode by default so dont need to pass --fast or --transpile-only flags.

correct me if something is missed.

https://github.com/TypeStrong/ts-node#cli-and-programmatic-options says --transpile-only is false by default.

That’s correct. There was a period of time it was the default for performance reasons, but I received a lot of issues because it differed from typescript. You’ll need the flag or use the register file for it.

So the new summary of this thread is:

Go ahead and use ts-node in production; just set the --transpile-only flag.

Is that correct?

For anyone wondering how to pass in --transpile-only when requiring ts-node in a node call:

node -r ts-node/register/transpile-only src/index.ts

A little bit about transpileModule for the curious: https://github.com/microsoft/TypeScript/blob/master/src/services/transpile.ts#L17

In this mode, files are only transpiled without typechecking, greatly improving compilation speed. All this means is your console won't spit out TypeError warnings, but if you use VSCode you already get realtime warnings within the editor.

A user early in this thread said that reflect-metadata broke when using this in -T (at the time it was -F) mode. Is this still the case?

EDIT: It looks like this is still a problem according to #873

Yes, it’s not possible to get type information if your compiling without type information - which is what transpile only does.

I haven't seen any issues with sequelize-typescript – the current limitation may be specifically limited to the enum issue described in #873.

General query to this thread: Out of curiosity, what are the arguments for not using ts-node in production ? Is there a good, important reason?

@iiian I don't think there is one, as long as you pass the correct flag disabling type checking. The one mentioned above may be outdated and I recommend you to check manual for the exact name.

Thumbs up if you're using ts-node in Production 😁

I am! 👍

Sad face if you're too afraid 😢

Thumbs up and sad face because going to production and afraid

Thumbs up and sad face because going to production and afraid

Same! Been migrating a node.js app to typescript. I tried running "tsc && node dist/app.js" but kept getting cannot find module from a local ts file. This is the only resort unfortunately, fingers crossed.

I deployed the other day and broke things :/ I build a video editor https://storycreatorapp.com and recently migrated my node server to TypeScript.

The reason it broke is that I was trying to get it to work with pm2.

Are you guys running your node.js servers in production without https://pm2.keymetrics.io/? That seems scary to me.

Has anyone gotten it to work with pm2?

@bluematter you'll probably have better luck in the TypeScript Community Discord: https://discord.com/invite/typescript
It's very active, with plenty of people answering questions. Be prepared to ask your question with sufficient detail, and you should get a good answer.