@hero-js/express-adapter
@hero-js/express-adapter
is an adapter for Express.js, allowing you to use Express.js as the underlying HTTP server for the Hero.js framework. With this adapter, you can seamlessly integrate Hero.js with Express.js to build powerful web applications and APIs.
Features
- Adapt Hero.js routers to work with Express.js.
- Handle results and wrap Express middleware seamlessly.
- Customize router configurations for different endpoints.
Installation
To use @hero-js/express-adapter
in your Hero.js project, you need to install it as a dependency. You can do this using npm or yarn:
npm install @hero-js/express-adapter
# or
yarn add @hero-js/express-adapter
Usage
To get started with this adapter, you'll need to follow these steps:
- Import the necessary modules:
const express = require('express');
const { ExpressAdapter, Router } = require('@hero-js/express-adapter');
- Create an instance of the
ExpressAdapter
class:
const expressApp = express();
const adapter = new ExpressAdapter(expressApp);
- Set up your Hero.js routers and configure them:
const router1 = new Router({ basePath: '/api/v1' });
// ... Define routes and middleware for router1 ...
const router2 = new Router({ basePath: '/auth' });
// ... Define routes and middleware for router2 ...
// Add routers to the adapter
adapter.setRouter(router1);
adapter.setRouter(router2);
- Adapt the routers to work with Express:
adapter.adapt().then((expressApp) => {
// Start the Express app
const port = process.env.PORT || 3000;
expressApp.listen(port, () => {
console.log(`Express app listening on port ${port}`);
});
});
- Run your Hero.js application using Express as the HTTP server.
Configuration
You can customize your router configurations by passing RouterOptions
when setting up routers. This allows you to configure things like middleware, error handling, and more.
Documentation
For detailed documentation, API references, and usage examples, please visit the official documentation.
Contributing
If you'd like to contribute to @hero-js/express-adapter
, please follow our contribution guidelines.
License
This package is open-source software licensed under the MIT License.