3

I'm getting starting with Node.js and Webstorm 7.0.3. I have created a simple Node.js app with express and I run it locally. I want to edit and save a .js file, refresh the broswer, and see the changes. As I understand it, this should pretty much work out-of-the box.

Here is what does work:

  • I start the Node.js server
  • I navigate to an express path with Chrome
  • The page renders correctly.

Here is what doesn't work:

  • I change the JavaScript function that renders the page
  • I save the file
  • I refresh the browser
  • The Web page does not reflect the changes to the JavaScript function

Here are the directions I followed from the JetBrains help site:

  • Create a Node.js run/debug configuration called "app.js"
    • Check the "After launch" and "with Javascript debugger" options
  • Create a JavaScript Debug configuration called "app.js.JavaScript
  • Select "Debug" for the "app.js" configuration.
  • The Node.js server starts
  • Select "Debug" for the "app.js.JavaScript.
  • I can now hit breakpoints in the application.

However, if I change the JS function that renders the page, save the file, and refresh the browser, the changes do not appear.

Configuration:

  • WebStorm 7.0.3
  • Chrome w/ JetBrains plugin 2.0
  • Windows 8
  • Node.js
    • express 3.4.8
    • hjs
ahoffer
  • 6,347
  • 4
  • 39
  • 68

2 Answers2

1

When you say you "change the JavaScript function that renders the page", I'm assuming that function is a route function that is on the server. E.g.:

exports.form = function (req, res) {
    res.render('login', { title: 'Login', message: req.flash('error') });
};

Changes to any server-side code do not automatically get picked up when refreshing the browser. You typically have to restart the server in order for those changes to take effect.

However, look into nodemon. Nodemon watches the filesystem for changes and automatically restarts the server if it detects something changed. Very useful for development.

Also, take a look at this post to see how to integrate nodemon with WebStorm:

How can I run nodemon from within WebStorm?

Community
  • 1
  • 1
Lukas S.
  • 5,698
  • 5
  • 35
  • 50
  • Nice. I added nodemon from the node.js command prompt. Then edited the "app.js" configuration. I changed the node interpreter to "C:\Users\ahoffer\AppData\Roaming\npm\nodemon.cmd". The server is automatically started when I change to the route function. – ahoffer Feb 09 '14 at 00:20
0

There is a module called hotswap (https://github.com/rlidwka/node-hotswap) that also looks promising - essentially, you access your module's methods through the hotswap module, which checks for changes behind the scenes for you. You access your module's methods through the hotswap object, and if a change has happened, it's reflected without restarting the server.

I haven't dug very deep into the module itself, but I can imagine there's memory issues (Node caches required modules on load, I'm not sure how it cleans them up) and possibly performance issues. Great for development, not sure you'll want it in production.

Sessamekesh
  • 420
  • 1
  • 6
  • 10