Book Image

NW.js Essentials

Book Image

NW.js Essentials

Overview of this book

If you are an experienced Node.js developer who wants to create amazing desktop applications using NW.js, this is the book for you. Prior knowledge of HTML5, jQuery, and CSS is assumed.
Table of Contents (11 chapters)
10
Index

Live reloading NW.js


While developing the frontend of the application, it comes in really handy to be able to reload the application interface at each change in the code. There are many approaches to live reload; let's see a couple of them.

If you're working on a single folder, all you need to do is leverage Node.js by adding the following code snippet directly at the end of your file:

<script>
var path = './',
  fs = require('fs');
fs.watch(path, function() {
  if (location) location.reload();
});
</script>

If you need a more complete solution by watching files recursively, you'll have to adopt a watch library, such as Gaze, Gulp, or Chokidar. Let's see another example, leveraging Gulp this time. First, you need to install Gulp (manually or through the manifest file) and then add the following piece of code at the end of your file:

<script>
var gulp = require('gulp');
gulp.task('reload', function () {
  if (location) location.reload();
});
gulp.watch('**/*', ['reload']);
...