Converting any JS project to TS backend

First step if you are setting up from scratch

✅ 1. Initialize Your Node.js Project

bash
npm init -y

Creates a package.json file.

Conversion start now

✅ 2. Install TypeScript and Types for Node

bash
npm install –save-dev…


This content originally appeared on DEV Community and was authored by keshav Sandhu

First step if you are setting up from scratch

✅ 1. Initialize Your Node.js Project

bash
npm init -y

Creates a package.json file.

Conversion start now

✅ 2. Install TypeScript and Types for Node

bash
npm install --save-dev typescript @types/node

  • typescript: the TypeScript compiler
  • @types/node: type definitions for Node.js (so fs, path, etc. work)

✅ 3. Initialize TypeScript Config

bash
npx tsc --init

This generates a tsconfig.json. You can use the default, but you might want to tweak a few settings.

Recommended tsconfig.json tweaks:

jsonc
{
"compilerOptions": {
"target": "es2020",
"module": "commonjs",
"outDir": "./dist",
"rootDir": "./src",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true
},
"include": ["src"]
}

✅ 4. Create Your Project Structure

bash
mkdir src
touch src/index.ts

Add a simple example in src/index.ts:

ts
const greet = (name: string) => {
console.log(Hello, ${name}!);
};

greet("TypeScript");

✅ 5. Compile TypeScript

bash
npx tsc

This compiles your TypeScript to JavaScript in the dist folder.

✅ 6. Run the Compiled JavaScript

bash
node dist/index.js

🔁 Optional: Add NPM Scripts

Edit package.json to make your workflow easier:

json
"scripts": {
"build": "tsc",
"start": "node dist/index.js",
"dev": "tsc --watch"
}

Now you can run:

bash
npm run build # Compile
npm start # Run
npm run dev # Watch and recompile on changes

🧪 Optional: Use ts-node to Run TS Directly (without compiling)

Install it:

bash
npm install --save-dev ts-node

Run TypeScript directly:

bash
npx ts-node src/index.ts


This content originally appeared on DEV Community and was authored by keshav Sandhu


Print Share Comment Cite Upload Translate Updates
APA

keshav Sandhu | Sciencx (2025-10-16T12:55:04+00:00) Converting any JS project to TS backend. Retrieved from https://www.scien.cx/2025/10/16/converting-any-js-project-to-ts-backend/

MLA
" » Converting any JS project to TS backend." keshav Sandhu | Sciencx - Thursday October 16, 2025, https://www.scien.cx/2025/10/16/converting-any-js-project-to-ts-backend/
HARVARD
keshav Sandhu | Sciencx Thursday October 16, 2025 » Converting any JS project to TS backend., viewed ,<https://www.scien.cx/2025/10/16/converting-any-js-project-to-ts-backend/>
VANCOUVER
keshav Sandhu | Sciencx - » Converting any JS project to TS backend. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/10/16/converting-any-js-project-to-ts-backend/
CHICAGO
" » Converting any JS project to TS backend." keshav Sandhu | Sciencx - Accessed . https://www.scien.cx/2025/10/16/converting-any-js-project-to-ts-backend/
IEEE
" » Converting any JS project to TS backend." keshav Sandhu | Sciencx [Online]. Available: https://www.scien.cx/2025/10/16/converting-any-js-project-to-ts-backend/. [Accessed: ]
rf:citation
» Converting any JS project to TS backend | keshav Sandhu | Sciencx | https://www.scien.cx/2025/10/16/converting-any-js-project-to-ts-backend/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.