Skip to content

Latest commit

 

History

History
67 lines (47 loc) · 2.15 KB

debugging.md

File metadata and controls

67 lines (47 loc) · 2.15 KB

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/

Debugging with Visual Studio Code

Debugging Feathers with Visual Studio Code
Learn how to setup an excellent, free debugger for your Feathers application. This guide also covers some basics for those who are new to debugging and/or Feathers.

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 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.