← Back to remy/nodemon

How to Deploy & Use remy/nodemon

Nodemon Deployment and Usage Guide

Prerequisites

  • Node.js (version 10.0.0 or higher)
  • npm (version 5.0.0 or higher) or Yarn
  • Git (for cloning the repository)

Installation

Global Installation (Recommended for Development)

npm install -g nodemon
# or using yarn
yarn global add nodemon

Local Installation (For Project Dependencies)

npm install --save-dev nodemon
# or using yarn
yarn add nodemon -D

Cloning the Repository

git clone https://github.com/remy/nodemon.git
cd nodemon
npm install

Configuration

Configuration Files

Nodemon supports configuration through nodemon.json files in the following locations:

  1. Global config - ~/.nodemon.json
  2. Local config - ./nodemon.json (in project root)
  3. Package.json - under nodemonConfig property

Example Configuration

{
  "verbose": true,
  "ignore": ["*.test.js", "**/fixtures/**"],
  "execMap": {
    "rb": "ruby",
    "pde": "processing --sketch={{pwd}} --run"
  }
}

Environment Variables

Nodemon doesn't require specific environment variables, but you can use standard Node.js environment variables like NODE_ENV for your application.

Build & Run

Basic Usage

Replace node with nodemon in your command line:

nodemon ./server.js localhost 8080

With Package.json

If your package.json has a main property or scripts.start:

nodemon

Manual Restart

While nodemon is running, type rs and press Enter to manually restart the application.

Watching Specific Extensions

nodemon --exec "python -v" ./app.py

Debug Mode

nodemon --inspect ./server.js 80

Deployment

Development Environment

For local development, simply use nodemon as a replacement for node:

nodemon npm start

Production Environment

Important: Nodemon is designed for development only. For production, use standard process managers:

# Use PM2 for production
pm2 start ecosystem.config.js

Or use Docker with a production-ready process manager:

FROM node:18-alpine

WORKDIR /app

COPY package*.json ./
RUN npm ci --only=production

COPY . .

EXPOSE 3000
CMD ["node", "server.js"]

Platform-Specific Deployment

Heroku: Add a Procfile with standard node command:

web: node server.js

Docker: Use multi-stage builds for production:

# Development stage
FROM node:18-alpine AS development
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
CMD ["nodemon", "server.js"]

# Production stage
FROM node:18-alpine AS production
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
CMD ["node", "server.js"]

Troubleshooting

Common Issues and Solutions

1. Nodemon Not Found

Issue: nodemon: command not found Solution: Ensure nodemon is installed globally or use npx nodemon for local installations.

2. Configuration Not Loading

Issue: Custom config settings not being applied Solution: Check the configuration file location and syntax. Use nodemon --config path/to/config.json to specify a custom config file.

3. File Watching Not Working

Issue: Changes not being detected Solution: Verify the watch property in your config includes the correct directories. Check file permissions.

4. Process Not Restarting

Issue: Application exits cleanly but doesn't restart Solution: Ensure restartable is set to always in your config, or use the manual restart command (rs).

5. Port Already in Use

Issue: "Error: listen EADDRINUSE" Solution: Check for other running instances or configure a different port in your application.

6. Debug Mode Not Working

Issue: --inspect flag not functioning Solution: Ensure Node.js version supports inspector protocol (v6.3.0+). Use --inspect-brk for breaking on startup.

Debug Logging

Enable verbose logging for troubleshooting:

nodemon --verbose

Or set the environment variable:

DEBUG=nodemon* nodemon ./server.js

Configuration Priority

Remember the configuration priority order:

  1. Command line arguments
  2. Local config file (nodemon.json)
  3. Global config file (~/.nodemon.json)
  4. Package.json nodemonConfig section