What is the best practice of deploying NodeJS server written in TypeScript to production?
I want to avoid having 3 files (ts, js, map) for every script in my git repository.
I could use grunt/gulp to create "dist" directory and copy all the compiled files there, but then I would have them in my repo anyways. I could create separate repo just for the compiled code, but thats not ideal as well I think.
Also, when I run node app.ts
without the js or the map existing, it actually starts up everything fine. So are the compiled files even needed for node server?
Note: I am dont have any compilation script/task in place, my IDE is compiling the ts files automatically for me.
TypeScript is well-established in the Node. js world and used by many companies, open-source projects, tools and frameworks. Some of the notable examples of open-source projects using TypeScript are: NestJS - robust and fully-featured framework that makes creating scalable and well-architected systems easy and pleasant.
You can use typescript to do all of this for you
tsconfig.json
{
...
"outDir": "dist",
"sourceMap": false,
"declaration": false
}
outDir
will compile the files into a dist directorysourceMap
will determine whether to output .map
filesdeclaration
will determine whether to output .d.ts
filesMore options can be found here and information on using a tsconfig.json
file can be found here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With