# nodemon

***

**1. Simple Node.js Server with Nodemon for Automatic Restart**

```js
const express = require('express');
const app = express();
const PORT = 3000;

app.get('/', (req, res) => {
  res.send('Hello World!');
});

app.listen(PORT, () => {
  console.log(`Server listening on port ${PORT}`);
});
```

**2. Nodemon with TypeScript and Jest**

```ts
// tsconfig.json
{
  "compilerOptions": {
    "target": "es2018",
    "module": "commonjs",
    "esModuleInterop": true,
    "outDir": "dist"
  },
  "include": ["src"],
  "exclude": ["node_modules"]
}

// package.json
{
  "scripts": {
    "start": "nodemon dist/index.js",
    "test": "jest"
  }
}
```

**3. Nodemon with Babel for ES Modules**

```js
// .babelrc
{
  "presets": ["@babel/preset-env"],
  "plugins": ["@babel/plugin-proposal-class-properties", "@babel/plugin-transform-runtime"]
}

// package.json
{
  "scripts": {
    "start": "nodemon --es-module-type=esm src/index.js"
  }
}
```

**4. Nodemon with Hot Module Replacement (HMR)**

```js
// index.js
const express = require('express');
const app = express();

if (module.hot) {
  module.hot.accept();
}

app.get('/', (req, res) => {
  res.send('Hello World!');
});

app.listen(3000);
```

**5. Nodemon with Debugger Support**

```js
// package.json
{
  "scripts": {
    "start": "nodemon --inspect index.js"
  }
}
```

**6. Nodemon with TypeScript and Jest (Advanced)**

```ts
// tsconfig.json
{
  "compilerOptions": {
    "target": "es2018",
    "module": "commonjs",
    "esModuleInterop": true,
    "outDir": "dist"
  },
  "include": ["src"],
  "exclude": ["node_modules"]
}

// jest.config.js
{
  "transform": {
    "^.+\\.tsx?$": "ts-jest"
  },
  "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$",
  "moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"]
}

// package.json
{
  "scripts": {
    "start": "nodemon dist/index.js",
    "test": "jest"
  }
}
```

**7. Nodemon with Watchlist for Custom Files**

```js
// package.json
{
  "scripts": {
    "start": "nodemon --watch schemas/*.json index.js"
  }
}
```

**8. Nodemon with Node.js >= 16 for ESM Support**

```js
// index.js
import express from 'express';

const app = express();
const PORT = 3000;

app.get('/', (req, res) => {
  res.send('Hello World!');
});

app.listen(PORT, () => {
  console.log(`Server listening on port ${PORT}`);
});
```

**9. Nodemon with Custom Ignore Patterns**

```js
// package.json
{
  "scripts": {
    "start": "nodemon --ignore '**/node_modules/**' --ignore '**/build/**' index.js"
  }
}
```

**10. Nodemon with Environment Variables**

```js
// package.json
{
  "scripts": {
    "start": "nodemon --env MONGO_URI=mongodb://localhost:27017, DB_NAME=my-app index.js"
  }
}
```

**11. Nodemon with Custom Restart Command**

```js
// package.json
{
  "scripts": {
    "start": "nodemon --exec 'ts-node src/index.ts'"
  }
}
```

**12. Nodemon with Babel and ESLint**

```js
// .eslintrc.json
{
  "parser": "@babel/eslint-parser",
  "parserOptions": {
    "requireConfigFile": false,
    "sourceType": "module"
  }
}

// package.json
{
  "scripts": {
    "start": "eslint src --ext .js,.ts,.jsx,.tsx && nodemon src/index.js"
  }
}
```

**13. Nodemon with Webpack and Live Reload**

```js
// webpack.config.js
module.exports = {
  entry: './src/index.js',
  output: {
    path: __dirname + '/dist',
    filename: 'bundle.js'
  },
  devServer: {
    contentBase: './dist',
    hot: true
  }
}

// package.json
{
  "scripts": {
    "start": "webpack-dev-server --hot",
    "watch": "webpack --watch --progress"
  }
}
```

**14. Nodemon with Dotenv**

```js
// .env
FOO=bar
```

```js
// index.js
const dotenv = require('dotenv');

dotenv.config();

console.log(process.env.FOO);  // Output: bar
```

**15. Nodemon with Delay Between Restarts**

```js
// package.json
{
  "scripts": {
    "start": "nodemon --delay 2 index.js"
  }
}
```

**16. Nodemon with Custom Logging**

```js
// package.json
{
  "scripts": {
    "start": "nodemon --log-file log.txt --log-level info index.js"
  }
}
```

**17. Nodemon with Type Checking for TypeScript**

```ts
// tsconfig.json
{
  "compilerOptions": {
    "target": "es2018",
    "module": "commonjs",
    "esModuleInterop": true,
    "outDir": "dist"
  },
  "include": ["src"],
  "exclude": ["node_modules"]
}

// package.json
{
  "scripts": {
    "start": "nodemon --exec 'tsc && node dist/index.js'"
  }
}
```

**18. Nodemon with BrowserSync for Live Reload**

```js
// package.json
{
  "scripts": {
    "start": "browser-sync start --server --files 'dist/**/*.html' --proxy 'http://localhost:3000'"
  }
}
```

**19. Nodemon with Parcel Bundler**

```js
// package.json
{
  "scripts": {
    "start": "parcel serve src/index.js --open"
  }
}
```

**20. Nodemon with ESLint and Prettier**

```js
// .eslintrc.json
{
  "extends": ["eslint:recommended", "prettier"],
  "plugins": ["prettier"]
}

// .prettierrc.json
{
  "printWidth": 80,
  "tabWidth": 2,
  "singleQuote": true,
  "trailingComma": "all"
}

// package.json
{
  "scripts": {
    "start": "eslint src/**/*.js src/**/*.ts && prettier --write src/**/*.js src/**/*.ts && nodemon src/index.js"
  }
}
```

**21. Nodemon with Mocha and Chai for Testing**

```js
// package.json
{
  "scripts": {
    "start": "nodemon",
    "test": "mocha --require ts-node/register --recursive 'src/**/*.test.ts'",
    "watch": "mocha --watch --require ts-node/register --recursive 'src/**/*.test.ts'"
  }
}
```

**22. Nodemon with pm2 for Process Management**

```js
// package.json
{
  "scripts": {
    "start": "pm2 start index.js --name my-app"
  }
}
```

**23. Nodemon with Vite for Fast Development**

```js
// package.json
{
  "scripts": {
    "dev": "vite",
    "build": "vite build"
  }
}
```

**24. Nodemon with Quasar Framework**

```js
// package.json
{
  "scripts": {
    "dev": "quasar dev",
    "build": "quasar build"
  }
}
```

**25. Nodemon with NestJS for Server-Side Applications**

```js
// package.json
{
  "scripts": {
    "start": "nodemon src/main.ts",
    "dev": "nest start --watch",
    "build": "nest build"
  }
}
```
