Search code examples
node.jscloud9-idemeanjs

How to start the Cloud9 debugger with MeanJS


newbie warning...

I followed a good tutorial (from FreeCodeCamp) to setup a new Mean.JS stack in Cloud9. https://vimeo.com/123488494

The tutorial says to start the application by running the command:

npm start

Which works just fine... except that the debugger doesn't attach and I can't use breakpoints, etc.

What magic am I missing?


Solution

  • Figured it out on my own, sort of (no, it didn't take all 2 days). Here's the detailed "whats up" for the future newbies to stumble on this...

    The tutorial said to start the app with the npm command:

    npm start
    

    For some reason not yet clear to me, npm calls the "start script" that is specified in package.json at the path... /scripts/start (and some other stuff... read the manual).

    The default install had this in the scripts section:

       "scripts": {
          "start": "grunt",
          "test": "grunt test",
          "postinstall": "bower install --config.interactive=false"
       },
    

    So...

    npm start
    

    is really just a fancy way of running...

    grunt
    

    Grunt is a "javascript task runner", which looks like it runs the javascript in gruntfile.js - also populated by the default install.

    gruntfile.js has this entry:

    nodemon: {
        dev: {
            script: 'server.js',
            options: {
                nodeArgs: ['--debug'],
                ext: 'js,html',
                watch: watchFiles.serverViews.concat(watchFiles.serverJS)
            }
        }
    },
    

    At some point, grunt is firing off the node server startup command as evidenced by the output message:

    [nodemon] starting `node --debug server.js`
    

    ... But cloud9 is not respecting the --debug request for some reason... to many fancy indirections or something.

    So what I did was create a new cloud9 run configuration (Run (menu) > Run Configurations > New Run Configuration):

    Name: debug
    Command: server   <<<  this just executes server.js
    Runner: Node.js
    

    Then I can use this to debug. It does seem to be working ok, but just a few minutes into it at this point. There does seem to be a bunch of stuff that is skipped by starting the app this way... but the debugger sure does come in handy. I'll try to use this just when I want to debug.

    I love learning new technologies... just wish it was faster.

    b.t.w. if anyone has a better solution or more experienced perspective on this, I'd be happy to mark a good response as the answer!

    ON EDIT 2 hrs after posting

    Another nice side effect of this alternate run approach is that it takes WAY less memory to run!!!! I no longer get the warning messages asking me to upgrade my precious cloud 9 free account.