An open API service indexing awesome lists of open source software.

https://github.com/somnathkar000/basic-ts-setup

This repository demonstrates a minimal setup for running TypeScript files seamlessly using nodemon and ts-node. The configuration allows automatic compilation and execution of TypeScript files whenever changes are detected.
https://github.com/somnathkar000/basic-ts-setup

basic-setup nodejs nodemon ts-node

Last synced: about 1 year ago
JSON representation

This repository demonstrates a minimal setup for running TypeScript files seamlessly using nodemon and ts-node. The configuration allows automatic compilation and execution of TypeScript files whenever changes are detected.

Awesome Lists containing this project

README

          

# Basic-TS-Setup πŸš€

A minimal TypeScript setup using **nodemon** and **ts-node** for seamless development.

## Features

- πŸ”„ **Live reloading** with `nodemon`
- πŸ“Œ **No manual compilation** using `ts-node`
- πŸ“‚ Watches `.ts` files inside the `src/` directory

## Installation & Usage

### 1️⃣ Install dependencies

```sh
npm install

2️⃣ Start development mode

npm run dev

3️⃣ Project Structure

πŸ“ explore-ts
┣ πŸ“ src
┃ β”— πŸ“œ index.ts # Entry point
┣ πŸ“œ package.json
┣ πŸ“œ nodemon.json
β”— πŸ“œ README.md

Configuration

package.json

{
"name": "explore-ts",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"dev": "nodemon"
},
"devDependencies": {
"nodemon": "^3.1.9",
"ts-node": "^10.9.2"
}
}

nodemon.json

{
"watch": ["src"],
"ext": "ts",
"exec": "ts-node ./src/index.ts"
}
```

In the nodemon.json file, these fields are configuring how Nodemon watches and restarts your TypeScript application. Here’s what each field means:

1. watch: [β€œsrc”]

- This tells Nodemon to watch the "src" directory for any changes.
- If any file inside "src" changes, Nodemon will restart the application.

2. "ext": "ts,js"

- Specifies the file extensions that Nodemon should watch.
- In this case, it only watches .ts (TypeScript) files.
- If you also wanted to watch JavaScript files, you could use:

```sh
"ext": "ts,js"
```

3. exec: β€œts-node ./src/index.ts”
- This is the command Nodemon executes when restarting.
- It runs ts-node ./src/index.ts, which compiles and runs the TypeScript file index.ts using ts-node.

How It Works
- If any .ts file in src/ changes, Nodemon automatically restarts ts-node ./src/index.ts.

Notes

- Ensure you have Node.js installed.
- The entry file should be src/index.ts.
- Modify nodemon.json to watch additional files if needed.