javascript - Node.js 服务器重启基础知识错误处理

标签 javascript node.js server

我正在研究 php7 和 node.js,以确定哪一个更适合我的任务。我读到有关 Node.js 在抛出错误时需要重新启动服务器的内容。

假设我在网站中使用了许多库,因此可能会出现错误。

我在node.js中读到,我可以将数据存储在变量中而不是数据库中,并在下一次调用中使用变量中的数据。如果我错了,请纠正我,到目前为止我从未使用过node.js。

现在抛出错误并导致该服务器需要重新启动。

然后我读到有一些工具可以重新启动服务器,例如。这个工具叫做“永远”。但现在我的问题-->

我的服务器的下一个实例是否可以保持旧实例的状态,或者变量中的数据是否会丢失?

或者我是否必须通过构造函数中的“永远”之类的工具或服务器下一个实例的某些工具来传递这些数据?我猜这将是意大利面条代码。

如果由于错误请求而引发错误,并且其他请求仍在处理并且服务器因错误而关闭,那么所有请求都会超时或返回某些内容吗?

非常感谢您为我澄清事情

最佳答案

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.

你错了。尽管您可以将数据存储在变量中并重用它们,但 Node 并不像您想象的那样工作。

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 constrctor or something of the next instance of the server? I guess this would be spaghetti code.

您需要一个数据存储,例如 mysql 或 redis 等数据库

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?

他们会被杀死。

您必须像在您正在编写的所有其他程序中一样添加错误处理。正确编写的程序应该很少甚至永远不会关闭,因为您可以捕获所有错误

关于javascript - Node.js 服务器重启基础知识错误处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39316748/

相关文章:

javascript - o.bind.apply(参数);

javascript - 如何将多个 svg 图标捆绑到 1 个文件中?

php - 下拉列表中页面加载时已选择的选项,也可更改

node.js - 如何在除静态 Assets 之外的所有路由上运行中间件

javascript - OrientDB Javascript 服务器端函数

javascript - 视差效果不起作用

javascript - 如何在 base64 编码的图像上使用 tesseract.js

javascript - Nodejs 一次触发两个请求

c - mq_receive 消息太长

java - 为什么Java nio消耗CPU过多?