FeathersJS — A framework that will spoil you

FeathersJS is a relatively new server-side framework that came out on top of Node and Express. It’s signature feature it’s that it’s super lightweight.

It contains a simple and logical workflow that streamlines building apis and can make an api that would have taken hours and builds it in minutes. It hits the perfect balance of magic and control where you still have full control over how your api behaves but the tools provided make your life so much easier. Feathers has two core features: services and hooks.

Services

Services are adaptors you can reuse such as running queries and updates in a MongoDB or Sequelize database. They contain your basic methods like create, find, get, update, remove that map to the REST post, get, put, and delete methods. FeathersJS has dozens of free ones to choose from and it’s easy to make your own.

app.use('/users', service(options));

Hooks

Hooks are methods that run before or after the interaction with the service allowing you to modify the incoming data or outgoing results. Hooks are easy to make and you have access to all the kind of information you would like. Feather’s has some convenient built it authentication hooks that you can prevent requests from continuing if they aren’t logged in.

const auth = require('feathers-authentication').hooks;
const common = require('feathers-hooks-common');
const userService = app.service('/users');
userService.before({
all: [],
find: [
auth.verifyToken(),
auth.populateUser(),
auth.restrictToAuthenticated(),
],
get: [
auth.verifyToken(),
auth.populateUser(),
auth.restrictToAuthenticated(),
],
create: [
auth.hashPassword(),
common.lowerCase('email')
],
update: [
auth.verifyToken(),
auth.populateUser(),
auth.restrictToAuthenticated(),
],
patch: [
auth.verifyToken(),
auth.populateUser(),
auth.restrictToAuthenticated(),
],
remove: [
auth.verifyToken(),
auth.populateUser(),
auth.restrictToAuthenticated(),
]
});

Command Line Interface

Feathers contains a CLI to quickly scaffold a new project or apis. You can specify which databases you want to use and what kind of authentication settings you would like.

Conclusion

Feathers allows you to focus on the models of your data and quickly setup reusable hooks to use across your apis. It means you don’t have to rewrite a lot of custom code for each endpoint you setup. With the scaffolding tool you can have a working api in minutes.

Check out the framework: feathersjs.com