Sunday, March 12, 2017

Visual Studio Code Tips and Tricks March 2017 - Working with Node

Debugging like a pro

Add a launch configuration to enable Node debugging.

{
    // Use IntelliSense to learn about possible Node.js debug attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version""0.2.0",
    "configurations": [

        {
            "type""node",
            "request""launch",
            "cwd""${workspaceRoot}",
            "name""API",
            "program""${workspaceRoot}/service/lib/hapi/index.js",
            "env": {
                "JWT_SECRET""hapi land",
                "FE_HOSTNAME""https://localhost",
                "MONGODB_CONFIG""mongodb://localhost/mydb"
            }
        }
    ]
}

You can have more than one launch config and browser support is available.

Documentation with JSDoc

VSCode enables JSDoc all over the editor with intellisense, in version 1.10, type /** to add a JSDoc annotation.
/**
 * Verifies authorizations
 * @param {string} accessRequest - The ACL in context
 * @param {string} configPre - The name of the prereq containing the config
 * @param {boolean}   denyUnauthorization - Returns 401 if unauthorized
 */
exports.checkAuthorizations = (accessRequest, configPre, denyUnauthorization) =>
    (request, reply) => { ... }

Quick Actions

These work like code refactoring, just like Resharper and Visual Studio. 


Debugger pane and console

Like Chrome Inspector, you get access to a REPL console, Variables, Watch, Call Stack, Breakpoints and some other nice things like auto display of a variable value.