Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lando Node.js + Express Example Reflecting File Changes in Browser #77

Closed
bgonz opened this issue Mar 21, 2018 · 3 comments
Closed

Lando Node.js + Express Example Reflecting File Changes in Browser #77

bgonz opened this issue Mar 21, 2018 · 3 comments
Assignees

Comments

@bgonz
Copy link

bgonz commented Mar 21, 2018

Feature Request / Guidance

As a lando user who wants to begin developing Node.js + Express apps locally, I would like a way to have the browser reflect my recent file changes.

I used the Example -> https://github.com/lando/lando/tree/master/examples/express

  • this loads up just fine and I can get the Landing page to load "I said "Oh my!" What a marvelous tune!" which is awesome
  • BUT now I am trying to understand how to update the files and see the changes in my browser.

I made an edit to the "app.js" in my local file system -> I can see it made the change to the Docker Container -> 'lando ssh appserver' -> cat app.js ... "I said "Oh my!" What a marvelous tune! Bingo Bango Bongo Baby!" (as edited on my local file system)

But refreshing the Browser does not seem to update the message. What am I missing? The only way I can get the browser to reflect the changes is to 'lando restart' which is unpleasant to do for quick iterative changes. Outside of Lando - I have had success with using PM2 (http://pm2.keymetrics.io/) with my Node.js + Express app.

It would be awesome if the Express Example had a prebuilt tool for monitoring for changes.

@dustinleblanc - mentioned possibly using Webpack for HotReloading
@serundeputy - mentioned npm script in the app like build or something; then you can do lando npm build and it will rebuild the served app on changes, but you have to get that or write it.

I tried doing a simple 'npm start' and the equivalent 'node app.js' but both seem to fail.

If it helps at all - here is what I use for just a normal Docker setup using Docker Compose:

version: '3'
services:
  # Node.js + Express Application
  node-app:
    build: ./node-app
    image: node-app
    ports:
      - "3000:3000"
    volumes:
      - "./node-app/src:/node-app"
      # This will map /node-app/node_modules to an anonymous volume maintained by docker
      # 'docker volume ls' -> long UUID
      - /node-app/node_modules
  # PM2 Process Deamon for Node.js + Express Application
  process-manager:
    image: keymetrics/pm2
  # Reverse Proxy Web Server
  nginx:
    build: ./nginx/
    image: nginx
    ports:
      - "80:80"
    volumes:
      - "./nginx/nginx.conf:/etc/nginx/conf.d/default.conf"
```

-- /node-app/Dockerfile

```
FROM node

# Install Global Dependencies
RUN npm install pm2 -g
RUN npm install gulp-cli -g
RUN npm install bower -g

# Create app directory
RUN mkdir -p /node-app
WORKDIR /node-app

# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY ./src/package*.json /node-app/
RUN npm install --production
# Bower
COPY ./src/public/javascripts/bower.json /node-app/public/javascripts/
WORKDIR /node-app/public/javascripts
RUN bower install --allow-root

# If you are building your code for production
# RUN npm install --only=production

# Bundle app source
WORKDIR /node-app
COPY ./src /node-app

EXPOSE 3000
# CMD [ "npm", "start" ]
# Use PM2 for Process Management + Reliability of our Application
CMD ["pm2-runtime", "./bin/www"]
```
@pirog pirog self-assigned this Mar 25, 2018
@vincenzo
Copy link

I am not too sure I get much of this. But I am running node.js apps in Lando, with npm run dev, where our dev command looks like this:

nodemon src/index.js --watch src --exec babel-node -e js,graphql --ignore *.test.js

Changing the code, reloads the app.

Is this what we're talking about? :D

@pirog
Copy link
Sponsor Member

pirog commented Mar 27, 2018 via email

@pirog
Copy link
Sponsor Member

pirog commented Mar 28, 2018

@bgonz so the mean example already has some autoreload baked into it but all this needs to be set up on the user side of things. We are using nodemon as pointed out by @vincenzo above so you'll probably want pass in arguments that make sense for your use case.

Going to update the express example to use nodemon as well so at least there is a very basic example of this working for people to follow.

@pirog pirog closed this as completed Mar 28, 2018
@rtfm-47 rtfm-47 transferred this issue from lando/lando Dec 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants