Start MongoDB from within a Grunt task

前端 未结 3 893
囚心锁ツ
囚心锁ツ 2020-12-30 00:12

Is it possible to start MongoDB from within a Grunt task? Basically when I\'m running my development environment with grunt server I want it to start up the Mo

3条回答
  •  难免孤独
    2020-12-30 00:47

    To add to JJJ's answer, using grunt-shell-spawn if you want to make sure each project has it's own mongodb instance with it's own data you would do this:

    shell: {
        mongodb: {
            command: 'mongod --dbpath ./data/db',
            options: {
                async: true,
                stdout: false,
                stderr: true,
                failOnError: true,
                execOptions: {
                    cwd: '.'
                }
            }
        }
    },
    

    The example also prints out only errors.

    You would then just add shell:mongodb to your grunt server task list (preferably the first task), add data to your .gitignore (assuming you're using git) and you're good to go.

提交回复
热议问题