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

我最近爱上了Gruntjs,并且乐于投入每一个使我的发展更容易的机会。 我目前正在编译我的SASS文件,运行手表,并使用nodemon保持我的节点服务器更新,因为我在应用程序上工作。

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

我目前已经尝试使用grunt-concurrent和grunt-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函数上运行asynchronous节点任务来完成,但我不想一直等待开发过程中的更改才能生效。 目前我一直在为数据库保留一个单独的shell选项卡,并且真的想把它集成到Grunt中,把所有东西放在一个地方。

我不确定这个问题的重要性,但是使用Node.js和MongoDB的人都会觉得这很有用。

谢谢

在指定“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", } } 

这对我有效。

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