简体   繁体   中英

node.js server restart fundamentals errorhandling

I'm researching about php7 and node.js to decide which one is better suited for my tasks. I read about node.js needs a server restart when a error gets thrown.

So lets say I use many libraries in my website, so a error is plausible.

I read in node.js I can store data in variables instead of in a database and use that data from the variables in the next call. Correct me if I'm wrong I never used node.js so far.

Now error gets thrown and cause of this server needs to be restarted.

Then I read there are tools that do that they restart the server eg. the tool called "forever". But now my questions -->

Does the next instance of my server can maintain the state of the old instance or does the data in the variables get lost?

Or do i have to pass this data via some tools like "forever" in the constructor or something of the next instance of the server? I guess this would be spaghetti code.

And if a error gets thrown in cause of wrong requests and there other requests still processing and the server shuts down cause of the error, will all requests time out or return something?

Thank you very much for making stuff clear for me

I read in node.js I can store data in variables instead of in a database and use that data from the varaibles in the next call. Correct me if I'm wrong I never used node.js so far.

You are wrong. Though you can store data in variables and reuse them, node doesn't work the way you are thinking.

Does the next instance of my server can maintain the state of the old instance or does the data in the variables get lost?

It gets lost

Or do i have to pass this data via some tools like "forever" in the constrctor or something of the next instance of the server? I guess this would be spaghetti code.

You need a datastore, a database like mysql or redis for example

And if a error gets thrown in cause of wrong requests and there other requests still processing and the server shuts down cause of the error, will all requests time out or return something?

They will be killed.

You have to add error handling like in every other program you're writing. A properly written program should shutdown very rarely to never, because you catch all your errors

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM