Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/34.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
Javascript 为什么Postgres会导致';[nodemon]清除退出-在重新启动前等待更改';?_Javascript_Node.js_Postgresql_Nodemon - Fatal编程技术网

Javascript 为什么Postgres会导致';[nodemon]清除退出-在重新启动前等待更改';?

Javascript 为什么Postgres会导致';[nodemon]清除退出-在重新启动前等待更改';?,javascript,node.js,postgresql,nodemon,Javascript,Node.js,Postgresql,Nodemon,当我试图运行我的“npm开始”脚本(使用localhost端口9000进行开发)时,我所有使用Postgres的项目(即使是我已经几周或几个月没有接触过的项目)都会崩溃。唯一的错误指示是“[nodemon]清除退出-在重新启动之前等待更改” 但是,在我的server/index.js文件中,当我替换以下内容时: db.sync() .then(() => { console.log(chalk.blue('database is synced!')); app.list

当我试图运行我的“npm开始”脚本(使用localhost端口9000进行开发)时,我所有使用Postgres的项目(即使是我已经几周或几个月没有接触过的项目)都会崩溃。唯一的错误指示是“[nodemon]清除退出-在重新启动之前等待更改”

但是,在我的server/index.js文件中,当我替换以下内容时:

db.sync()
  .then(() => {
    console.log(chalk.blue('database is synced!'));
    app.listen(PORT, (err) => {
      if (err) throw err;
      console.log(chalk.green(`server running on ${PORT}`));
    });
  });
仅使用app.listen部分:

app.listen(PORT, (err) => {
  if (err) throw err;
  console.log(chalk.green(`server running on ${PORT}`));
});
然后,应用程序至少可以在本地主机端口9000上加载和访问(尽管显然没有需要数据库的功能)

我有一些项目使用相同的启动程序/样板代码(和相同的脚本),但是使用Mongoose/MongoDB可以很好地处理所有数据库功能,而且没有问题。我已经多次确保我的导入/导出是一致的(同样,代码本身在几周内没有改变)

我还尝试了以下方法:

db.sync()
  .then(() => {
    console.log(chalk.blue('database is synced!'));
    app.listen(PORT, (err) => {
      if (err) throw err;
      console.log(chalk.green(`server running on ${PORT}`));
    });
  });
  • 测试多个项目并构建每个项目都使用Postgres的新启动代码
  • 停止Postgres服务器并终止所有Postgres进程(使用'sudo pkill-u Postgres'和'pkill Postgres'终端命令)
  • 卸载Postgres应用程序(我最初直接从postgresql网站下载),删除所有Postgres文件夹,删除Postgres CLI工具的路径,重新安装并重新初始化上述程序
  • 验证我的应用程序是否连接到与我的Postgres服务器相同的端口(默认端口5432)
  • 我仍然能够初始化和启动Postgres服务器。Postgres CLI工具仍然有效,我仍然能够创建新数据库并使用这些工具执行基本操作,因此我不确定我的应用程序为什么会出现问题。提前感谢您的帮助,我对您的长消息表示歉意。我将在下面添加其他代码以供参考:

    #server/db/index.js-注意:下面的导出作为“db”导入顶部代码段,我可以在运行Postgres服务器时确认名为“boiler”的数据库存在

    const Sequelize = require('sequelize');
    const chalk = require('chalk');
    
    const DB_NAME = 'boiler';
    
    module.exports = new Sequelize(process.env.DATABASE_URL || `postgres://localhost:5432/${DB_NAME}`, {
      logging: false,
    });
    
    package.json脚本-种子设定也不起作用,但运行种子设定脚本不会产生任何错误消息

      "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1",
        "start": "webpack -w & nodemon server/index.js",
        "build": "webpack",
        "db-init": "pg-init boiler",
        "postinstall": "npm run db-init",
        "seed": "node server/db/seed.js"
      },