Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 写入ECONREET错误_Node.js - Fatal编程技术网

Node.js 写入ECONREET错误

Node.js 写入ECONREET错误,node.js,Node.js,我看了我的问题的一些可能的答案,但我找不到解决它的方法 当我调用localhost:3000/users/create_account时,我有一个错误ECONNRESET。 它涉及这项服务: router.post('/create_account', function (req, res, next) { const results = []; client.connect(); // Grab data from http request const data = { username:

我看了我的问题的一些可能的答案,但我找不到解决它的方法

当我调用localhost:3000/users/create_account时,我有一个错误ECONNRESET。 它涉及这项服务:

router.post('/create_account', function (req, res, next) {
const results = [];
client.connect();

// Grab data from http request
const data = {
username: req.body.username, name: req.body.user,
firstname: req.body.firstname, email: req.body.email,
location: req.body.location
};

// Get a Postgres client from the connection pool
client.connect('error', function (err, data) {
// Handle connection errors
if (err) {
  done();
  console.log(err);
  return res.status(500).json({ success: false, data: err });
}

const queryInsert = 'INSERT INTO Users(username, name,'
  + 'firstname, email, location) values($1, $2, $3, $4, $5)';
const values = [data.username, data.name,
data.firstname, data.email, data.location];

// SQL Query > Insert Data into Users 
client.query(queryInsert, values, (err, res) => {
  if (err) {
    console.log(err.stack)
  } else {
    query.on('end', () => {
      done();

      Promise.all([queryInsert])
        .then(() => client.end()).catch(err => console.log(err));
      return res.json(results);
    });
  };
});
请问,有人知道是什么原因造成的,以及如何解决这个问题吗

这是完全错误:

Error: write ECONNRESET
at _errnoException (util.js:992:11)
at Socket._writeGeneric (net.js:764:25)
at Socket._write (net.js:783:8)
at doWrite (_stream_writable.js:397:12)
at writeOrBuffer (_stream_writable.js:383:5)
at Socket.Writable.write (_stream_writable.js:290:11)
at Socket.write (net.js:707:40)
at Connection._send (C:\Users\Amaris\Desktop\NodeJS_Projects\basefugees-dev-backend\node_modules\pg\lib\connection.js:198:24)
at Connection.password (C:\Users\Amaris\Desktop\NodeJS_Projects\basefugees-dev-backend\node_modules\pg\lib\connection.js:190:8)
at C:\Users\Amaris\Desktop\NodeJS_Projects\basefugees-dev-backend\node_modules\pg\lib\client.js:98:9
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! basefugees-dev-backend@0.0.1 start: `node ./bin/www node`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the basefugees-dev-backend@0.0.1 start script.
npm ERR! This is probably not a problem with npm. There is likely additional 
logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Amaris\AppData\Roaming\npm-cache\_logs\2018-07- 11T14_05_26_893Z-debug.log
和my package.json:

{
  "name": "basefugees-dev-backend",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node ./bin/www node",
    "database": "node ./models/database",
    "test": "mocha"
  },
  "dependencies": {
    "body-parser": "^1.18.3",
    "cookie-parser": "~1.4.3",
    "debug": "~2.6.9",
    "dotenv": "^6.0.0",
    "express": "~4.16.0",
    "http-errors": "~1.6.2",
    "morgan": "~1.9.0",
    "pg": "^6.1.0",
    "pg-hstore": "^2.3.2"
  },
  "devDependencies": {
    "chai": "^4.1.2",
    "mocha": "^5.2.0"
  }
}

您似乎没有遵循正确的API进行错误处理。从中,没有将字符串作为第一个参数的
client.connect()
重载。它可能试图将该值用作密码或基于错误堆栈的其他配置值

您想要使用的是:

client.on('error', (err) => { 
   // do whatever.  Though again you're calling a `done` that doesn't seem defined, and some other concerns. 
});

您似乎没有遵循正确的API进行错误处理。从中,没有将字符串作为第一个参数的
client.connect()
重载。它可能试图将该值用作密码或基于错误堆栈的其他配置值

您想要使用的是:

client.on('error', (err) => { 
   // do whatever.  Though again you're calling a `done` that doesn't seem defined, and some other concerns. 
});

您可以发布完整的错误日志吗?您是否通过npm start运行它?如果是,请共享package.json。您在以下行中定义了
query
query.on(…
?我没有看到它的定义,您的错误可能是吞咽了一个简单的错误,因为它不在范围内。好的,但与
客户端
,以及其他可能的客户端一样。您是否发布了所有相关的代码?您是否尝试运行简单的sql命令,如
选择1
,以查看您是否确实能够从nod连接到postgrese?我假设您的错误发生在这一行
客户端。connect('error',function(err,data){
您可以发布完整的错误日志吗?您是否通过npm start运行它?如果是,请共享package.json。您在这一行中定义
query
query.on(…
?我没有看到它的定义,您的错误可能是吞咽了一个简单的错误,因为它不在范围内。好的,但与
客户端
,以及其他可能的客户端一样。您是否发布了所有相关的代码?您是否尝试运行简单的sql命令,如
选择1
,以查看您是否确实能够从nod连接到postgrese?我假设您的错误发生在这一行
客户端。connect('error',function(err,data){
就是这样!谢谢大家。我对node.js有点陌生,所以我还在学习抱歉:/哦,是这样!谢谢大家。我对node.js有点陌生,所以我还在学习抱歉:/