Can I make nodejs work after each modification without restarting server - node.js

I'm new to Node.js. For each modification in code, I have to restart server to make it work. I wonder if there are any ways to make it work without restarting server. Thanks.

Check out this npm plugin: https://npmjs.org/package/devreload
There is also a very cool NodeJS based framework called Meteor which does all of this automatically. It is very easy to learn, and does realtime code & content updates. I suggest looking into that as well.
Good luck.

I have not come across any which deploys server side scripts without restarting the server. There are node packages like Forever, Nodemon which listens to changes and deploys automatically.

Related

How to hot reload on netlify?

Netlify just as example, same question with CloudFlare Pages etc.
In the past I setup my own server with node and react/vue.
I have my node setup on a server because I don't want to install node and node packages on my local machine.
When I was developing I SSH into the server with port forwarding.
So I ran a dev server on port 8888 (npm run dev) on the server and opened http://localhost:8888 in my local browser.
When I make a change to the files I can immediately see the effects without running npm run build.
I am thinking about using a service like netlify because its the right thing to do? But how can I see the changes I make without actually running build?
Is this even possible or do you use theses service only when you are building a website that rarely changes? I am probably missing something. But not sure how to proceed.
I don't know what's the right way. I am very open to suggestions.
Edit: These services that I mentioned are meant for build only. See answer below. I am still leaving this question so people can post suggestions.
You cannot do this. Those services are only for hosting the build version of your app. You have to develop it locally and push the build to these services.
Why would you even want to run a development version online?

Do I have to stop the react native server everytime I want to install a new node module

React noobie here.
I have a question, I am working on a react native project, and I search for extensions I can add for my applications, whenever I want to install a new module, I have to stop the server and let the installation finish, then run the server again. This process takes too much time, is there a way I can circumvent that?
Yes it is good because the restart assures that all new files are added at the start of the app. I think it is a good thing even though it can be annoying but installing dependecies when the app is running would only make it harder to code imo.

Can ember-cli watch and re-run my server code too?

So I have a simple Ember.js app which communicates with a node.js server using websockets. The stream server doesn't serve the actual ember app - just various bits of data. Can I have ember-cli automatically re-run my server code when a file is changed inside it?
My workflow is currently
ember s
node ./stream_server/index.js -p 4201
Now I can edit frontend stuff and have everything automatically update. Great! However, if I make a change to my server code, I have to manually go in and C-c it, and re-run node ./stream_server/index.js -p 4201. This gets kind of boring when I know that somewhere in Ember, there's a watcher that's already doing this for frontend stuff.
So, any chance of this working? Or do I just use some other watcher tool to do it?
Cheers,
Carl

Meteor running on my own infrastructure

After reading the Meteor official documentation regarding this subjet, I would like to know if it's possible to change my code, deploy the new version, but without restarting the node js server? My idea is to have a development server, where I make my updates, and then after testing commit the changes to the real production server, so that I don't break anything.
If this doen't make any sense, what is the current best approach to accomplish the same results?
Thanks a lot for the help.
You should not need to reset the node js server. Any changes to the code will be injected into the client's browser.
From Meteor main page:
Hot Code Pushes.
Update your app while users are connected without disturbing them. When you push a new version, the new code is seamlessly injected into each browser frame in which the app is open.

Should node.js changes be instantaneous?

Seeing how node.js is ultimately javascript, shouldn't changes to any files be seen when trying to run the app command? I've forked the yuidocjs repo on github and am trying to work my way through my local build, but for some reason my minor changes do not get picked up. I'm new to node.js so I'm not really sure what the exact conventions are.
In node.js when you require a file the source code gets interpreted. It's considered good practice to require all code when you start the server so all the code gets interpreted once.
The code does not get re-interpreted whenever you run it though.
So changes are not instantaneous.
To help you out, try supervisor which does hot reloading of the server on code changes.
It is possible to make instant changes happen by re-interpreting source code but that is not the default action. Generally you should just re-start the server.
Also see nodemon which will automagically reload changed files under it's authority.
EDIT
Rereading your question, it appears you are asking about the following scenario:
Run app to test
Quit app to refactor js code
Restart app
And you're asking why your changes do not appear at step 3?
If this is the case, you are seeing something very strange which might be related to how and from where files are being required.
In node, run:
console.dir(require.paths);
To see where node is looking for any resources you are requiring. If there is a copy of the file you're changing in any of the paths listed which is not the file you're editing, this would explain your problem.

Resources