Gruntjs - 以特定顺序运行多个阻止任务(Mongo& Node.js)

时间:2013-10-10 16:02:27

标签: node.js mongodb shell terminal gruntjs

我最近对Gruntjs表示了爱意,并且很高兴地抓住每一个机会让我的发展生活变得更加轻松。我目前正在编译我的SASS文件,运行监视器,并使用nodemon在我处理应用程序时更新节点服务器。

所以这就是我早上开车自己疯狂的地方。我想在Node应用程序运行之前启动MongoDB。在Node应用程序的设置中,我检查数据库中的任何值,如果它是空的,则将充满信息的测试文件推送到表中。

我目前尝试使用grunt-concurrentgrunt-shell-spawn来运行必要的mongo和node命令。

grunt.initConfig({
  shell: {
    mongo: {
      command: 'mongo'
    },
    node: {
      command: 'node app.js'
    }
  },
  concurrent: {
    dev: {
      tasks: ['shell:mongo','shell:node'],
      options: { logConcurrentOutput: true }
    }
  }
});
grunt.loadNpmTasks('grunt-concurrent');
grunt.loadNpmTasks('grunt-shell-spawn');

有没有办法确保mongo命令在运行节点任务之前达到“阻塞”状态?我猜这可以通过在setTimeout函数上运行节点任务异步来完成,但我不想一直等待看到开发过程中的更改生效。目前我一直在为数据库打开一个单独的shell选项卡,并且非常希望将它集成到Grunt中以将所有内容保存在一个地方。

我不确定它在大范围内的重要性,但是任何使用Node.js和MongoDB的人都会发现它非常有用。

由于

2 个答案:

答案 0 :(得分:0)

在指定“options:{async:true}”时尝试使用grunt-nodemon和shell:mongo

concurrent: {
        tasks: ['shell', 'nodemon'],
        options: {
            logConcurrentOutput: true
        }
    },
    shell: {
        mongo: {
            command: 'mongod',
            options: {
                async: true
            }
        }
    },
nodemon: {
        dev: {
            script: "server.js",
        }
    }

这对我有用。

答案 1 :(得分:-2)

您可以间隔检查mongodb的服务端口以查看它是否可访问?\

相关问题