I’ve googled this to death. I see other people have the same problem, i’ve tried their solution, but it’s not working for me. The problem in a nutshell is that i’m running a container with a node app. I use nodemon to see changes to my code ‘live’, I can see that the changes to the code are being detected since the console says this every time i save a change in the code:
- When i make a change, it does not update in my browser, I have to manually refresh the page to see the change.
dashboard-app | [nodemon] restarting due to changes…
dashboard-app | [nodemon] starting node app.js
dashboard-app | Server is running on http://localhost:3000
Here is my code. Let’s start with my docker-compose.yml for the app:
dashboard-app:
container_name: dashboard-app
build: .
ports:
- "3000:3000"
environment:
- CHOKIDAR_USEPOLLING=true
- WATCHPACK_POLLING=true
volumes:
- .:/usr/src/app # Mount your project directory correctly
- /usr/src/app/node_modules
command: nodemon -L app.js
networks:
- my-network
restart: always
Than my Dockerfile:
FROM node:16
# Set working directory
WORKDIR /usr/src/app
# Copy package.json and package-lock.json
COPY package*.json ./
# Install all dependencies
RUN npm install
# Copy all other files
COPY . .
# Install nodemon globally
RUN npm install -g nodemon
# Expose port 3000
EXPOSE 3000
# Command to run nodemon
CMD ["npm", "start"]
and my package.json:
{
"name": "my-node-dashboard",
"version": "1.0.0",
"description": "A dashboard for business tools and stats",
"main": "app.js",
"scripts": {
"start": "nodemon -L app.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.18.2"
},
"devDependencies": {
"nodemon": "^2.0.22"
}
}
I believe that this is everything affecting this perticular problem.
Anyone see any errors? Or have a tip for solving it?
Other solutions to this problem mainly revolve arround using the -L tag in the nodemon command.
And / OR adding enviroment chokidar_usepolling=true. This has not worked for me.
3
Answers
consider adding
to your package.json
This file should resolve the issue:
nodemon won’t refresh your browser, it only tracks server changes.
Please see answer here or here. You need to setup something like
livereload
,browsersync
, etc. along with nodemon to make it work