Overview of Lunox Laravel-Flavoured Node.js Framework
Lunox is a Node.js framework designed to provide a 'Laravel-flavoured' experience, aiming to support basic Laravel features while maintaining simplicity for Node.js developers.
website·Indexed 30 days ago
https://lunox.js.orgA JavaScript framework inspired by Laravel, featuring a service container, facades, an Artisan command-line console, and a query builder. It provides comprehensive tools for routing, middleware, controllers, validation, and error handling for building HTTP-driven applications.
resources/views directory. Lunox leverages Vite for automatic conversion of template files to JavaScript and supports Hot Module Replacement (HMR) during development.polka for the HTTP server and vite for frontend tooling. Key architectural features include support for facades, macros, service containers, middleware, and artisan commands, making it a bridge for Laravel developers transitioning to Node.js.artisan.ts file, which loads the Console Kernel and initializes the application in a console environment.index.ts). The kernel's startup process involves: loading global helper functions from autoload.ts, bootstrapping the application, loading configuration, and registering/booting all service providers.The RedirectResponse instance provides methods to store temporary data in the session that is deleted after the next request:
with(data): Flashes custom data to the session. Access it via req.session().get('key').withInput(): Flashes the current request's input data to the session (useful for validation errors). Access it via req.session().old('key').// Flash custom error message
return redirect('someurl')->with({
error: 'Some Error Message'
});
// Access via: req.session().get('error')
// Flash current request input
return back()->withInput();
// Access via: req.session().old('username')handle methods can accept additional parameters after req and next. These parameters are passed in the route definition by appending a colon and a comma-separated list of values to the middleware alias.// Middleware definition
class ExampleMiddleware implements Middleware {
async handle(req, next, param1, param2) {
console.log(param1, param2);
return next(req);
}
}
// Route definition
Route.get("/example", () => "OK").middleware("example:param1,param2");pnpm dev script to run your Lunox application in development mode. This command creates and watches files in the dist directory and starts the application on localhost:8000 by default. The default port can be modified in the .env file.pnpm devredirect() helper to send a user to a specific URL, or the back() helper to redirect them to the previous URL. Both return an instance of RedirectResponse.// Redirect to a specific path
Route.post("/login", () => {
return redirect("/dashboard");
});
// Redirect to the previous URL
return back();