BlogBlog JungleworksJW Blog

Migrating Code From Javascript To Typescript (NodeJS)

By Deepak Digwal 15th September 2020

Make your NodeJS Typescript code Production Ready

Add Typescript To your existing project

  1. npm install -g typescript
  2. tsc -i– this will create tsconfig.json file
  3. Add following code into jsconfig.json file

Points to take note of

  1. Make sure that all of your typescript code that you want to convert to typescript is inside src folder.
  2. Start converting each file to typescript by renaming the extension to .ts and then convert the code to typescript.
  3. Once you have converted all the files to typescript remove set "allowJs": false in compilerOptions .

Running Code in Production

  1. Once you are done with converting the code. Type tsc this will convert the entire code in src folder to javascript in dist folder.
  2. Now to run your code in production use the following command pm2 start dist/app.js -i 0

Author: Raviteja

Visit the link to read more from Raviteja: https://medium.com/@raviteja.nitj

Subscribe to stay ahead with the latest updates and entrepreneurial insights!

  • Share this article:

  • Blog Jungleworks Blog Jungleworks Blog Jungleworks