Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@feathersjs/feathers
Advanced tools
A framework for real-time applications and REST API with JavaScript and TypeScript
@feathersjs/feathers is a lightweight web framework for building real-time applications and REST APIs using JavaScript or TypeScript. It provides a flexible architecture for creating services that can be used on the client and server, making it easy to build scalable and maintainable applications.
Service Creation
This code demonstrates how to create a basic service in FeathersJS. The service has methods for finding, getting, and creating messages. The service is then registered with the Feathers application and used to create a new message.
const feathers = require('@feathersjs/feathers');
const app = feathers();
// A simple service that logs and returns the message
class MessageService {
async find() {
return [];
}
async get(id) {
return { id, text: `A new message with ID: ${id}` };
}
async create(data) {
return data;
}
}
app.use('messages', new MessageService());
app.service('messages').create({ text: 'Hello Feathers' }).then(message => {
console.log('Created message', message);
});
Hooks
This code shows how to use hooks in FeathersJS. Hooks are middleware functions that can be run before or after a service method. In this example, a 'before' hook is used to log the data before a message is created.
const feathers = require('@feathersjs/feathers');
const app = feathers();
// A simple service
class MessageService {
async create(data) {
return data;
}
}
app.use('messages', new MessageService());
// A hook that logs the data before creating a message
app.service('messages').hooks({
before: {
create: async context => {
console.log('Creating message', context.data);
}
}
});
app.service('messages').create({ text: 'Hello Feathers' });
Real-time Functionality
This code demonstrates how to add real-time functionality to a FeathersJS application using Socket.io. The application is configured to use Socket.io, and a service is created that publishes events to all connected clients whenever a new message is created.
const feathers = require('@feathersjs/feathers');
const socketio = require('@feathersjs/socketio');
const app = feathers();
app.configure(socketio());
// A simple service
class MessageService {
async create(data) {
return data;
}
}
app.use('messages', new MessageService());
app.on('connection', connection =>
app.channel('everybody').join(connection)
);
app.publish(data => app.channel('everybody'));
app.service('messages').create({ text: 'Hello Feathers' });
Express is a minimal and flexible Node.js web application framework that provides a robust set of features for web and mobile applications. While Express is more general-purpose and widely used for building web servers and APIs, FeathersJS builds on top of Express to provide additional real-time and service-oriented features.
Hapi is a rich framework for building applications and services in Node.js. It is known for its powerful plugin system and configuration-driven approach. Compared to FeathersJS, Hapi offers more built-in features for building complex applications but may require more setup for real-time capabilities.
Koa is a new web framework designed by the team behind Express, aiming to be a smaller, more expressive, and more robust foundation for web applications and APIs. Koa uses async functions to eliminate callback hell and improve error handling. Unlike FeathersJS, Koa does not have built-in real-time features but provides a more modern approach to middleware.
Feathers is a lightweight web-framework for creating APIs and real-time applications using TypeScript or JavaScript.
Feathers can interact with any backend technology, supports many databases out of the box and works with any frontend technology like React, VueJS, Angular, React Native, Android or iOS.
You can build your first real-time and REST API in just 4 commands:
$ npm create feathers my-new-app
$ cd my-new-app
$ npm start
To learn more about Feathers visit the website at feathersjs.com or jump right into the Feathers guides.
Copyright (c) 2024 Feathers contributors
Licensed under the MIT license.
FAQs
A framework for real-time applications and REST API with JavaScript and TypeScript
The npm package @feathersjs/feathers receives a total of 78,540 weekly downloads. As such, @feathersjs/feathers popularity was classified as popular.
We found that @feathersjs/feathers demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.