DZone
Java Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Java Zone > Development Trick: Auto-updating & Auto-reloading

Development Trick: Auto-updating & Auto-reloading

Remy Sharp user avatar by
Remy Sharp
·
Jun. 26, 12 · Java Zone · Interview
Like (0)
Save
Tweet
2.54K Views

Join the DZone community and get the full member experience.

Join For Free

For the upgrade of JS Bin to version 3 (an open beta), the whole code base is in the process of being rewritten to run as a Node.js process (whilst still working as a PHP application).

What’s neat is I’ve got it to automatically pull the latest changes from github and automatically restart my Node process.

I don’t claim this to be particularly clever, and I’m sure I should be able to trigger a pull on the server as a push happens, but this works fairly well for my development workflow (where the app needs to be online) and is pretty simple – which I like.

Commands

For those like me who don’t care about the detail, here’s exactly what I’m doing in the terminal:

$ cd /WWW/jsbin/
$ screen -S gitpull
$ watch git pull
CTRL+a d
$ screen -S jsbin
$ nodemon .
CTRL+a d

Here’s what’s going on.

Screen

I’m using a linux process called screen which simply put: creates a persistent shell that you can send to the background and retrieve at a later date. This means I can run my processes inside a screen and get them back any time I want if there’s some debugging to do.

Now I’ve got a way of managing two tasks:

  1. Pull from github for any changes
  2. Restart my node process

Once you’re inside screen to detach (and return to your original shell) you use the command sequence CTRL+a d.

Here’s a few extra simple commands:

  • screen -ls will show all the screen processes you’re running and the PIDs they have. You’ll need the PID to reattach the screen
  • screen -r<PID> so in my case: screen -r gitpull will reattach and put me back in to the screen

Auto-updating code

Inside one screen we make use of watch which will keep running a process every 2 seconds. So I “watch” the git pull command.

Obviously this is a bit crap because it’s trying to pull from github to no avail most of the time, but it does mean that when I push new code up, this process will automatically pull.

Which leads me on to restarting…

Auto-reloading

In another screen I’m running the development tool Nodemon to auto restart when any JavaScript files change (which come from the git pull).

So that’s it. Pretty simple.

 

Git Command (computing) GitHub shell app workflow Node.js IT

Published at DZone with permission of Remy Sharp, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • What Is URL Rewriting? | Java Servlets
  • Password Authentication: How to Correctly Do It
  • How to Submit a Post to DZone
  • The Most Popular Kubernetes Alternatives and Competitors

Comments

Java Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo