DEV Community

Cover image for How To Make A Typescript + NodeJS Express Project with eslint, EJS and Restart On Typescript Server Changes

How To Make A Typescript + NodeJS Express Project with eslint, EJS and Restart On Typescript Server Changes

Ritesh Kumar on June 27, 2022

Start with a clean project pnpm init or npm init -y Enter fullscreen mode Exit fullscreen mode ...
Collapse
 
attkinsonjakob profile image
Jakob Attkinson

Here are a couple of nooby questions:

should ts-node-dev watch the app.ts or the start command should look like this: "start": "npx tsc && ts-node-dev dist/src/app.js ?

Meaning, should we be watching the ts file or the compiled version?

If you deploy this app on production, how would you start the server?

Collapse
 
nyctonio profile image
Ritesh Kumar • Edited

no there is no need to add tsc in start script ts-node-dev do all the jobs but in production we should use our transpiled file as we have already type checked everything

Collapse
 
attkinsonjakob profile image
Jakob Attkinson

ts-node-dev doesn't transpile, does it? At least in my case, if I want to have the dist/build folder, I do need to manually run tsc

Thread Thread
 
nyctonio profile image
Ritesh Kumar

No, actually It does not transpile it automatically I will recommend you to create different scripts for development and production
"start:dev": "ts-node-dev src/app.ts",
"start": "tsc && node dist/app.js"

Thread Thread
 
attkinsonjakob profile image
Jakob Attkinson

Thank you!

Collapse
 
brense profile image
Rense Bakker

For a typescript project highly prefer ts-node-dev over nodemon
With your current start script, if you make a change to the typescript code it will not recompile automatically, you can fix that with nodemon, but ts-node-dev has no need to recompile your code, it will just serve the changed typescript immediately which is obviously much faster.

Collapse
 
brense profile image
Rense Bakker

Actually I just noticed you're doing stuff double... because you are using ts-node in your nodemon config you dont need to tsc before running nodemon. ts-node is also much slower than ts-node-dev though and you dont need to have nodemon at all, you can just add a script like this: "start": "ts-node-dev src/app.ts" and thats all you need.

Collapse
 
nyctonio profile image
Ritesh Kumar

Thank you for your insights I will check this out for sure

Collapse
 
tylim88 profile image
Acid Coder

I use babel-node to run typescript project

dev.to/tylim88/babel-node-typescri...

Collapse
 
nyctonio profile image
Ritesh Kumar

thank you for sharing