Debugging Your Feathers App

You can debug your Feathers app the same as you would any other Node app. There are a few different options you can resort to. NodeJS has a built in debugger that works really well by simply running:

node debug src/

Moar Logs!

In addition to setting breakpoints we also use the fabulous debug module throughout Feathers core and many of the plug-ins. This allows you to get visibility into what is happening inside all of Feathers by simply setting a DEBUG environmental variable to the scope of modules that you want visibility into.

  • Debug logs for all the things

      DEBUG=* npm start
    
  • Debug logs for all Feathers modules

      DEBUG=feathers* npm start
    
  • Debug logs for a specific module

      DEBUG=feathers-authentication* npm start
    
  • Debug logs for a specific part of a module

      DEBUG=feathers-authentication:middleware npm start
    

Using Hooks

Since hooks can be registered dynamically anywhere in your app, using them to debug your state at any point in the hook the chain (either before or after a service call) is really handy. For example,

const hooks = require('feathers-authentication').hooks;

const myDebugHook = function(hook) {
  // check to see what is in my hook object after
  // the token was verified.
  console.log(hook);
};

// Must be logged in do anything with messages.
app.service('messages').before({
  all: [
    hooks.verifyToken(),
    myDebugHook,
    hooks.populateUser(),
    hooks.restrictToAuthenticated()
  ]
});

You can then move that hook around the hook chain and inspect what your hook object looks like.

results matching ""

    No results matching ""