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

Already on GitHub? Sign in to your account

restart node.exe if dependent files are updated #58

Closed
kirillg opened this Issue Oct 11, 2011 · 20 comments

Comments

Projects
None yet
9 participants

kirillg commented Oct 11, 2011

Currently, IISNode restarts node.exe if the associated .js file is updated. Pretty common my app consists of the main app.js and some module foo.js that app.js depends on (require('foo.js').

As I debug issues in foo.js, I often update it without updating app.js. I have to remember to restart IISNode. Could we either
a) provide an explicit descriptor of dependencies
or, better yet,
b) track the .js files we load at runtime and re-load node.exe if any of the loaded .js filed got updated.
?

simtan commented Nov 9, 2011

I would support this - the default Node.js w/Express template in WebMatrix has this construct and every time you change routes.js you have to manually restart IISExpress. It's quite time-consuming...

How about adding a listener to all *.js files in the same directory as the one named in web.config? Or doing as Kirill says and understanding the require() dependencies (I know this is probably much harder)?

Owner

tjanczuk commented Jan 6, 2012

The fix is to add a new configuration attribute system.webServer\iisnode@watchedFiles. This is a semi-colon separated list of files that will be watched for changes. A change to a file causes the application to recycle. Each entry consists of an optional directory name plus required file name which are relative to the directory where the main application entry point is located. Wild cards are allowed in the file name portion only.

For example, if the main entry point to an application is deployed to c:\apps\myapp\server.js, and the web.config contains the following:

<iisnode watchedFiles="*.js;node_modules\foo\lib\options.json;app_data\*.config.json" />

Then changes to any of the following files will cause application recycle:

  • c:\apps\myapp*.js
  • c:\apps\myapp\node_modules\foo\lib\options.json
  • c:\apps\myapp\app_data*.config.json

The default value of iisnode@watchedFiles is "*.js", which means that changes to any *.js files located in the directory with the application entry point (e.g. server.js) will cause application recycle.

@tjanczuk tjanczuk closed this in 9982779 Jan 6, 2012

This doesn't seem to be working for me.

Collaborator

rramachand21 commented Jul 16, 2014

Please elaborate.

@rramachand21 when i deploy new files to my iisnode site, the app pool doesn't recycle.

Collaborator

rramachand21 commented Jul 16, 2014

Whats your watched files setting?

Collaborator

rramachand21 commented Jul 17, 2014

With the current implementation, watchedFiles will recycle node.exe if it detects changes to existing *.js files in your case. It will not detect new *.js files created.

@rramachand21 I'm using teamcity to deploy all files. Everything is overwritten each time. Also, I tried changing a .js file by adding a few white spaces and saving. The app still did not recycle.

I'm having the same problem as well...

Collaborator

rramachand21 commented Jul 17, 2014

I just tried the "changing a .js file by adding a few white spaces and saving." and the node.exe recycles on the next request. Do you have a simple app that repro's this issue?

Collaborator

rramachand21 commented Jul 17, 2014

btw, which version of iisnode are you using?

@rramachand21 when the node process recycles, does it start a new log file? In any case, I have no new log statements from the app.

How do I check the version of iisnode?

Collaborator

rramachand21 commented Jul 17, 2014

in your app, print process.pid and if the pid changes, you know your node.exe has recycled. To check iisnode version, go to %programfiles%\iisnode\iisnode.dll, right click this->properties->Details -- check file version.

@rramachand21 My version is 0.2.7.

I have a fair amount logging that should print every time the app starts. Modifying the .js files does not cause any logging at all.

Collaborator

rramachand21 commented Jul 18, 2014

Please give me a repro application as I am not able to repro with my setup and i am using 0.2.7 for my testing as well. Are you modifying *.js files in the same directory where the main script file is present. By main script file i mean the one you specified in your web.config as your entry point like server.js?

@rramachand21 sorry for the late reply.

Here's my web.config

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <iisnode nodeProcessCommandLine="&quot;c:\program files (x86)\nodejs\node.exe&quot;" watchedFiles="*.js" 
      interceptor="&quot;%programfiles%\iisnode\interceptor.js&quot;" />
        <handlers>
            <add name="iisnode" path="site.js" verb="*" modules="iisnode" />
        </handlers>

        <rewrite>
            <rules>
                <clear />
                <rule name="default">
                    <match url="/*" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
                    <action type="Rewrite" url="site.js" />
                </rule>
            </rules>
        </rewrite>

        <security>
            <requestFiltering>
                <hiddenSegments>
                    <add segment="node_modules" />
                </hiddenSegments>
            </requestFiltering>
        </security>
    </system.webServer>
</configuration>

Here's my site.js

 console.log(process.pid);

var http = require('http');
http.createServer(function (req, res) {
    console.log('here');
      res.writeHead(200, {'Content-Type': 'text/plain'});
      res.end('Hello World\n');
}).listen(process.env.PORT);

When I change site.js to

 console.log(process.pid);
 console.log(process.pid);
 console.log(process.pid);

var http = require('http');
http.createServer(function (req, res) {
    console.log('here');
      res.writeHead(200, {'Content-Type': 'text/plain'});
      res.end('Hello World\n');
}).listen(process.env.PORT);

nothing happens.

For some reason this doesn't work for me too. Even when I want to make a change to a single server.js file, sometimes it updates automatically but most of the time I need to restart it manually.

My starting point for my app is in a 'bin' folder. How would I specify files in the parent folder of the entry point? Would I use something like: '../*.js'

shushiej commented Nov 22, 2016 edited

has there been a fix to this, as I am also facing the same problem.
I am using express to start my server:
`const express = require('express');
const app = express();

app.use('/api/roadmaps', roadmapsRouter);

// Need to add a roadmapId as a paramater in the future
dbModule.updateRoadmapCards();

app.get('/', function root(req, res) {
res.sendFile(__dirname + '/index.html');
});

app.listen(process.env.PORT || 3000);
console.log('server started on port', process.env.PORT || 3000);`

And my web.config looks like this
`
<system.webServer>

 <!-- indicates that the hello.js file is a node.js application 
 to be handled by the iisnode module -->

 <handlers>
   <add name="iisnode" path="server.js" verb="*" modules="iisnode" />
 </handlers>

 <iisnode watchedFiles="web.config;*.js;index.html" nodeProcessCommandLine="C:\Program Files\nodejs\node.exe" />

 <rewrite>
   <rules>
     <rule name="api">
       <match url="api/*" />
       <action type="Rewrite" url="server.js" />
     </rule>
   </rules>
 </rewrite>

 <!-- exclude node_modules directory and subdirectories from serving
 by IIS since these are implementation details of node.js applications -->
 
 <security>
   <requestFiltering>
     <hiddenSegments>
       <add segment="node_modules" />
     </hiddenSegments>
   </requestFiltering>
 </security>    

</system.webServer>
`

This is a React based application and when i make a change to a any of my components under the path
/src/components//.js there doesnt seem to be a any change in the iisnode application, and I am not able to see any changes to the app. I tried manually restarting the IIS site but that didn't work either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment