Marble.js
repository·master·Indexed 24 days ago
https://github.com/marblejs/marbleA functional reactive Node.js framework for building server-side applications, built on TypeScript and RxJS. It provides a modular ecosystem including @marblejs/core, @marblejs/http, @marblejs/websockets, and @marblejs/messaging, along with specialized middlewares for logging, body parsing, I/O validation, CORS, and multipart file handling.
What's inside marblejs
- Marble.js is a functional reactive Node.js framework designed for building server-side applications. It is built using TypeScript and leverages RxJS to provide a reactive programming model for server-side logic.
Explore Marble.js integration examples
masterThe@marblejs/integrationpackage provides a collection of reference implementations demonstrating how to combine various Marble.js modules. These examples cover common architectural patterns such as REST APIs, CQRS with EventBuses, messaging with RabbitMQ/Redis, and WebSocket servers.Marble.js Ecosystem and Modules
masterMarble.js is composed of several specialized modules that can be used to build different parts of a server-side application:
@marblejs/core: The framework's core module.@marblejs/http: Provides HTTP capabilities.@marblejs/websockets: Provides WebSocket support.@marblejs/messaging: Provides messaging capabilities.@marblejs/testing: Provides testing utilities.@marblejs/middleware-logger: Logger middleware.@marblejs/middleware-body: Body parser middleware.@marblejs/middleware-io: I/O validation middleware.@marblejs/middleware-cors: CORS middleware.@marblejs/middleware-multipart: Multipart middleware.
Install @marblejs/websockets
masterInstall the
@marblejs/websocketsmodule using npm. This module requires@marblejs/core,rxjs, andfp-tsto be present in your project dependencies.$ npm i @marblejs/websocketsUse the CORS middleware in Marble.js
masterTo enable Cross-Origin Resource Sharing (CORS) in your Marble.js application, import
cors$from@marblejs/middleware-corsand include it in yourmiddlewaresarray when initializing yourhttpListener. This allows you to control which origins, methods, and headers are permitted for incoming requests.import { cors$ } from '@marblejs/middleware-cors'; const middlewares = [ logger$, cors$( { origin: '*', // Allow all origins methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'], optionsSuccessStatus: 204, allowHeaders: '*', // Allow all headers maxAge: 3600, } ) ]; const effects = [ endpoint1$, endpoint2$, ... ]; const app = httpListener({ middlewares, effects });Install @marblejs/middleware-body
masterInstall the
@marblejs/middleware-bodypackage via npm. This middleware requires@marblejs/coreand@marblejs/httpto be installed in your project to function correctly.$ npm i @marblejs/middleware-bodyInstall @marblejs/middleware-logger
masterInstall the logger middleware using npm. Note that this package requires
@marblejs/coreand@marblejs/httpto be installed in your project as dependencies.$ npm i @marblejs/middleware-loggerInstall @marblejs/middleware-io
masterInstall the IO validation middleware using npm. Note that this package requires
@marblejs/coreto be installed as a dependency.$ npm i @marblejs/middleware-ioInstall @marblejs/http
masterTo use the HTTP module in your Marble.js project, install it via npm. Note that this package has peer dependencies on
@marblejs/core,rxjs, andfp-tswhich must also be present in your project.$ npm i @marblejs/httpInstall @marblejs/middleware-multipart
masterInstall the multipart middleware using npm. This package requires
@marblejs/coreand@marblejs/httpto be installed in your project.$ npm i @marblejs/middleware-multipartInstall @marblejs/messaging
masterInstall the
@marblejs/messagingmodule using npm. This module requires@marblejs/core,rxjs, andfp-tsto be present in your project dependencies.$ npm i @marblejs/messagingManage dependencies using Context
masterMarble.js uses a
Contextobject to implement dependency injection. AContextis essentially a map where keys areContextTokens and values areContextDependencys. Dependencies can be provided in two ways:- Eager Dependencies (
ContextEagerReader): Evaluated immediately when the context is resolved. - Lazy Dependencies (
ContextLazyReader): Evaluated only when the dependency is looked up for the first time.
To build a context, you can use
createContext()to start with an empty context, and then useregister,registerAll,bindLazilyTo, orbindEagerlyToto populate it.- Eager Dependencies (