Please stop killing `node server.js` process when `.js` file is added!

In the console/terminal for an app, run ps -ux | grep server:

app@tree-jelly:~ 11:48 
$ ps -ux | grep server
app       1573  0.3  0.1 1128360 46804 ?       Sl   11:46   0:00 node server.js
app       1644  0.0  0.0  12944   932 pts/0    S+   11:48   0:00 grep server

Then, back in Glitch add a file to the project named myfile.html, and then run ps -ux | grep server again:

app@tree-jelly:~ 11:48 
$ ps -ux | grep server
app       1573  0.2  0.1 1128616 47296 ?       Sl   11:46   0:00 node server.js
app       1646  0.0  0.0  12944   976 pts/0    S+   11:50   0:00 grep server

Okay, it’s the same PID for node server.js. Which is good.

Now, back in Glitch add a file to the project named myfile.js, and then run ps -ux | grep server a third time:

app@tree-jelly:~ 11:50 
$ ps -ux | grep server
app       1667  6.3  0.1 1062584 45944 ?       Sl   11:51   0:00 node server.js
app       1705  0.0  0.0  12944   936 pts/0    S+   11:51   0:00 grep server

You will see that the PID for node server.js has changed. Which is bad.

This is a problem for me because in the node server.js process is where I have a custom chokidar watcher running, and it gets restarted when a .js file changes (or is added) before it gets a chance to kick off its build. I’m hoping I don’t have to implement any hacks to work around this, because I like having my watcher be part of server.js so that it gets integrated seamlessly with all the other auto stuff that Glitch does.

Is there a solution to my problem though, whether hack-y or not?

One peculiar observation is that I actually only observe this process restarting behavior for a brand new Glitch. If I walk away for >5 mins and come back after the app container has had a chance to shut down, then start it back up it again, then this process restarting problem magically goes away?

Anyone have any insight into this behavior I’m observing, or more importantly have a fix?

I need a fix because this is part of a workflow for people that will be new to Glitch. I will be having them import from GitHub and don’t want part of that tutorial process to be “walk away from the computer for 5 minutes before trying to edit any JavaScript files”.

I have tested this many times with new vanilla and import projects and it is consistently a reproducible problem.

The ‘refresh’ command restarts the backend of the editor, which is what happens when you come back to a sleeping project. Perhaps that will remove the need to wait for it to sleep?

Edited to reflect Tim’s much-better informed comment below!

I’ll try that! I also think manually editing the watch.json in the imported project might help, because adding watch.json to vanilla project seems to have helped vanilla.

Refresh only restarts the backend of the editor, so that’s probably not going to help.

The issue here is that we need to restart node to pick up your server-side code changes, restarting when you change a .js file is normally desirable. You can write a custom watch.json that will only restart node when your server-side files are changed. That’s probably the best approach.

I think the issue here is an imported watch.json is not detected by the Glitch watcher.

If Glitch scanned for watch.json creation after a GitHub import, then I think my issue would go away.

Currently I will have to tell people to create the watch.json manually, which is not actually ideal in my case.

Unfortunately refresh does not seem to be tied into the Glitch watcher. Need another command to tells the Glitch watcher to reload its config from watch.json. Is that something you guys can provide me? Perhaps rewatch, or just tie it into the refresh command? THANKS!

I think you guys need to run sv restart watcher on your end!

I’ll raise a feature request for this. In the mean time, it’d be useful to know the wider context of what you’re using this for. You mentioned folks new to Glitch would be importing projects from GitHub via a tutorial? What kind of project is it?

If you’re loading in your project as npm packages anyway, why not just have users remix and already configured Glitch project as opposed to importing from GitHub?

1 Like