Live updating server-side node code. #1498

Closed
opened 2025-08-09 17:20:22 +00:00 by fergalmoran · 0 comments
Owner

Originally created by @pauldotknopf on 7/20/2016

I just wrote a module that auto-reloads a javascript file in node by watching the file system.

hot-instance

I'd like this repo to be able to use this to avoid having to restart node to get new server-side code loaded.

Now, I could implement my own module that is called via InvokeAsync's moduleName parameter. However, my application is using the that parameter for other purposes (MVC Areas if you must), and I would like the live-updating happening before there.

I basically need to change the way this tidbit works.

I am curious on your thoughts on this. I could do a couple things.

  1. I could provide my own entry point script entirely with OutOfProcessNodeInstance, which I'd like to avoid because updates would break it.
  2. Modify HttpNodeInstanceEntryPoint to accept a command line parameter that indicates a module name that should be used to invoke the moduleName parameter and exportedFunctionName. Basically, a small layer of indirection. When starting a node instance, we can then do node http-entry.js -requireModule hot-instance-require.js. This new hot-instance-require.js would look something like this.
// hot-instance-require.js
module.exports = function(moduleName, exportedFunctionName, callback) {
    // custom module resolving and executing here that will executed the 'callback' parameter correctly
}

I would of course do the work, but I wanted to discuss it with you before I do this. Would you accept a pull request providing this feature? If so, what approach would you like me to take?

NOTE: I understand the risks of reloading a previously require'd node module, but in my case, I am using a file generated from webpack. All the modules used in the script are bundled in the single javascript file.

*Originally created by @pauldotknopf on 7/20/2016* I just wrote a module that auto-reloads a javascript file in node by watching the file system. [hot-instance](https://github.com/pauldotknopf/hot-instance) I'd like this repo to be able to use this to avoid having to restart node to get new server-side code loaded. Now, I could implement my own module that is called via [`InvokeAsync`](https://github.com/aspnet/JavaScriptServices/blob/fae0a886af70d26eac6939fe4ec3dcf50b5460ce/src/Microsoft.AspNetCore.NodeServices/INodeServices.cs#L8)'s `moduleName` parameter. However, my application is using the that parameter for other purposes (MVC Areas if you must), and I would like the live-updating happening before there. I basically need to change the way [this tidbit](https://github.com/aspnet/JavaScriptServices/blob/fae0a88/src/Microsoft.AspNetCore.NodeServices/TypeScript/HttpNodeInstanceEntryPoint.ts#L52) works. I am curious on your thoughts on this. I could do a couple things. 1. I could provide my own entry point script entirely with [`OutOfProcessNodeInstance`](https://github.com/aspnet/JavaScriptServices/blob/fae0a88/src/Microsoft.AspNetCore.NodeServices/HostingModels/OutOfProcessNodeInstance.cs#L33), which I'd like to avoid because updates would break it. 2. Modify `HttpNodeInstanceEntryPoint` to accept a command line parameter that indicates a module name that should be used to invoke the `moduleName` parameter and `exportedFunctionName`. Basically, a small layer of indirection. When starting a node instance, we can then do `node http-entry.js -requireModule hot-instance-require.js`. This new `hot-instance-require.js` would look something like this. ``` js // hot-instance-require.js module.exports = function(moduleName, exportedFunctionName, callback) { // custom module resolving and executing here that will executed the 'callback' parameter correctly } ``` I would of course do the work, but I wanted to discuss it with you before I do this. Would you accept a pull request providing this feature? If so, what approach would you like me to take? NOTE: I understand the risks of reloading a previously `require`'d node module, but in my case, I am using a file generated from webpack. All the modules used in the script are bundled in the single javascript file.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/JavaScriptServices#1498
No description provided.