Skip to content

pradeepbgs/mayajs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

99 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MayaJS

MayaJS is a simple and lightweight HTTP server library for Node.js, designed to give you control over your API routes and middleware in an intuitive and efficient way. With MayaJS, you can quickly set up a server, define routes, and optimize important routes for faster response times.

Features

  • Simple API: Easy-to-use methods for handling HTTP requests.
  • Middleware Support: Integrate middleware to process requests before they reach your handlers.
  • Async/Await Support: Handle asynchronous operations effortlessly.
  • Body Parsing: Enable request body parsing with a single method.

Installation

Install MayaJS via npm:

npm install mayajs

import Maya from "mayajs";
import { hello } from "./hello.js";

const maya = new Maya();
const port = 3000;

// Middleware example
maya.use(hello);


// Define routes
const { join } = require("path");
const filePath = join(__dirname, "static");

maya.get("/").handler((xl) => {
  // like this - return xl.json()
  // or like this
  return { msg: "Hello, world!" }
});

// Render a HTML page
maya.get("/render").handler(async (xl) => {
  return await xl.res.render(filePath, "index.html");
});

maya.get("/async-test").handler(async (xl) => {
  await new Promise((resolve) => setTimeout(resolve, 1000));
  return xl.res.json({ message: "Async operation completed" });
});

maya.get("/error-test").handler((xl) => {
  return xl.res.send("Hello, error handler!");
});

maya.get("/redirect").handler((xl) => {
  return xl.res.redirect("/");
});

maya.get("/hello/:id").handler((xl) => {
  const id = xl.req.params.id;
  return xl.res.json({ msg: "Hello", id });
});


// Start the server
maya.listen(port, () => {
  console.log(`MayaJS server is running on port ${port}`);
});

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published