If you’re diving into the realm of decentralized social networking, the ActivityPub-Express (APEX) middleware for NodeJS is your trusty sidekick. This modular implementation of the ActivityPub protocol provides a robust framework for building your own social network. Follow this guide to get started!
Installation
To kick things off, you need to install the APEX package. But there’s a twist! You will require a patched version of the http-signature library for request signing to work properly. Here’s how to install APEX:
- Run the following command to install:
npm install --save activitypub-express
- Then, ensure everything is in the right order with:
npm dedupe
Usage
Now, let’s set up APEX in your application. Imagine you are the maestro of an orchestra; your code will be the musical score they follow:
const express = require('express');
const MongoClient = require('mongodb').MongoClient;
const ActivitypubExpress = require('activitypub-express');
const port = 8080;
const app = express();
// Define your routes as if they were sections of your orchestral arrangement
const routes = {
actor: 'u:actor',
object: 'o:id',
activity: 's:id',
inbox: 'u:actorinbox',
outbox: 'u:actoroutbox',
followers: 'u:actorfollowers',
following: 'u:actorfollowing',
liked: 'u:actorliked',
// ... additional routes
};
// Compose your APEX instance
const apex = ActivitypubExpress({
name: 'Apex Example',
version: '1.0.0',
domain: 'localhost',
actorParam: 'actor',
objectParam: 'id',
activityParam: 'id',
routes,
endpoints: {
proxyUrl: 'https://localhost/proxy',
}
});
// Set the JSON and URL parsing middleware
app.use(
express.json({ type: apex.consts.jsonldTypes }),
express.urlencoded({ extended: true }),
apex
);
// Define routes using prepackaged middleware
app.route(routes.inbox)
.get(apex.net.inbox.get)
.post(apex.net.inbox.post);
// Additional route definitions...
client.connect()
.then(() => apex.store.db = client.db(DB_NAME))
.then(() => app.listen(port, () => console.log(`Apex app listening on port ${port}`)));
In this analogy, your code sets the stage for many actions, much like an orchestra reading from a score! Each route serves as a specific section that efficiently handles requests, such as getting an inbox or delivering objects.
Troubleshooting
Encountering issues? No worries! Here are some common troubleshooting tips:
- Error: InvalidHeaderError: bad param format – If you see this error during activity delivery, it might be tied to the request library not using the patched version of
http-signature. To fix this, run:
npm dedupe
For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.
Next Steps and Examples
Congratulations on setting up your ActivityPub server! But what comes next? The possibilities are plentiful:
- Server-to-server applications: You can define custom side-effects for incoming messages.
- Full platform experience: Consider adding user authentication using Passport.js for a full-fledged social platform.
- For inspiration, check out Guppe Groups, a federated social groups app built efficiently with just 250 lines of code.
- Or, explore Immers Space, a comprehensive social platform for virtual worlds.
Conclusion
At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.
With APEX, you’re well on your way to creating your own corner of the decentralized web!

