nanoexpress
GitHubKnown BugsFAQ
  • Getting Started
  • Server
  • Middlewares
  • Routes
    • Static Serve
    • Request
    • Response
    • Route
    • Errors handling
  • Schemas
  • WebSocket
  • Docker / Linux
  • Optimizations
  • Benchmarks
  • Known bugs
  • Sponsors
  • FAQ
  • License
Powered by GitBook
On this page
  • Route-middleware route
  • Async route
  • Basic Async example
  • DB example
  • Basic example
  • JSON example

Was this helpful?

  1. Routes

Route

Don't forget to return to HttpResponse from the route

Using many middlewares may slow response performance

Route-middleware route

import Route from 'nanoexpress/src/Route';

const route = new Route();

app.use(route);

route.get('/', async () => 'hello world');
const Route = require('nanoexpress/cjs/Route');

const route = new Route();

app.use(route);

route.get('/', async () => 'hello world');

if you want Route to work properly, first initialize via app.use(routerInstance) then registrate your routes

Async route

Basic Async example

app.get('/', async () => ({ status: 'success' }));

DB example

app.get('/', async (req, res) => {
  const result = await db.getUser(req.params.id);

  return result;
});

Basic example

app.get('/', async (req, res) => {
  return res.end('hello world');
});

JSON example

app.post('/', (req, res) => {
  const { body } = req;

  return res.send({ status: 'ok' });
});
PreviousResponseNextErrors handling

Last updated 9 months ago

Was this helpful?