使用Grunt启动服务器时,Node.js服务器文件console.log()未显示

时间:2016-11-10 15:46:19

标签: node.js gruntjs

我正在使用grunt命令启动我的节点应用程序。我的Gruntfile.js是:

module.exports = function(grunt) {

    grunt.initConfig({
       nodemon: {
           dev: {
               script: 'server.js'
           }
       },

       watch: {
             css: {
                 files: ['src/css/*.scss'],
                 tasks: ['sass:dev']
             },
             js: {
                 files: ['src/js/*.js'],
                 tasks: ['uglify:dev']
             }
       },    

       concurrent: {
            options: {
                logConcurrentOutput: true
            },
            tasks: ['nodemon','watch']
        }
    });

    grunt.loadNpmTasks('grunt-nodemon');
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-concurrent');
    grunt.registerTask('default',['concurrent']);
};

当我运行应用程序键入grunt时,我得到以下输出:

C:\Projects\SocialMeal>grunt
Running "concurrent:tasks" (concurrent) task
Running "nodemon:dev" (nodemon) task
Running "watch" task
Waiting...


[nodemon] v1.2.1
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node server.js`

然后,不会显示server.js上的每个console.log()调用。如果我使用node server.js启动应用程序,则会显示console.log()消息。

任何提示?

2 个答案:

答案 0 :(得分:1)

感谢greuze。问题是nodemon版本。将其更改为1.11.0并且console.log输出现在可以正常工作。

只需删除当前安装的版本:

npm uninstall grunt-nodemon

并更改了package.json:

"grunt-nodemon": "~1.10.0",

答案 1 :(得分:0)

我得到console.log输出。

我有一个内容为server.js的文件:

let name = 'Peter';

console.log(`My name is: ${name}`);

我使用了你的Gruntfile.js。

我在运行grunt后获得此输出:

Running "concurrent:tasks" (concurrent) task
    Running "watch" task
    Waiting...
    Running "nodemon:dev" (nodemon) task
    [nodemon] 1.11.0
    [nodemon] to restart at any time, enter `rs`
    [nodemon] watching: *.*
    [nodemon] starting `node index.js`
    My name is: Peter
    [nodemon] clean exit - waiting for changes before restart

请注意,有console.log输出。你确定你的过程没有被困在任何地方吗?