Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploying Typescript NodeJS Server

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.

like image 982
Tomas Avatar asked Feb 04 '16 23:02

Tomas


People also ask

Can TypeScript run on Nodejs?

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.


1 Answers

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 directory
  • sourceMap will determine whether to output .map files
  • declaration will determine whether to output .d.ts files

More options can be found here and information on using a tsconfig.json file can be found here

like image 187
SnareChops Avatar answered Oct 25 '22 09:10

SnareChops