Netpress Laravel-inspired backend framework for Node.js
Frameworkv0.1.14 Starterv0.1.12 Docsv1.0.3
Overview Installation Architecture CLI
Features

Routing

Netpress routing is built on Express routers plus a small wrapper that adds Laravel-style route groups and smart-response dispatch.

Quick Example

// routes/api.js
import { Router } from "@admicaa/netpress";
import authRoutes from "./auth.js";
import userRoutes from "./users.js";
import { db } from "../app/Providers/DatabaseServiceProvider.js";
import appConfig from "../config/app.js";

const router = Router();

router.get("/health", () => ({
  status: "ok",
  db: db.type,
  env: appConfig.env,
}));

router.group("/auth", (auth) => {
  auth.use("/", authRoutes);
});

router.group("/users", (users) => {
  users.use("/", userRoutes);
});

export default router;

Where Routes Mount

RouteServiceProvider mounts:

  • routes/web.js at / when config/view.js enables a web engine
  • routes/api.js under /api/v1

That means the example "/health" route above is served at /api/v1/health.

Router.group()

Router.group() accepts:

  • a prefix and a callback
  • one or more middleware functions and a callback
  • a prefix, one or more middleware functions, and a callback

Examples:

router.group("/api", (api) => {
  api.get("/health", () => ({ ok: true }));
});

router.group(authMiddleware, (protectedRoutes) => {
  protectedRoutes.get("/me", (req) => req.user);
});

router.group("/admin", [authMiddleware, requireRole("admin")], (admin) => {
  admin.get("/users", UserController.index);
});

Nested groups preserve parent params:

router.group("/users/:userId", (users) => {
  users.group("/posts", (posts) => {
    posts.get("/:postId", (req) => req.params);
  });
});

Smart Response Dispatch

Only the last non-error handler in a route is auto-dispatched. Earlier middleware stays untouched.

A terminal handler can return:

Return valueResult
plain object or arrayJSON
view(componentOrName, props)HTML
json(data, status?)JSON with explicit status
redirect(url, status?)redirect
stringtext/plain
Bufferraw body
number or booleanJSON
null or undefined204 No Content
restreated as already handled

Manual res.send, res.json, res.render, res.redirect, res.end, res.sendFile, res.download, and res.sendStatus continue to work normally.

Route Listing

The starter CLI can print every mounted route:

npm run artisan -- route:list

That is especially useful after adding nested groups or when web routes are conditionally mounted through config/view.js.