npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mr-mkz/axon

v0.4.3

Published

A backend library that aims to be simple and powerful.

Downloads

408

Readme

Axon.js

like the brain's powerful neural pathways, simple yet strong.

Axon is a backend library who tries to be simple and powerfull.

Currently Axon is 2X faster than Express. :D please checkout Axon Benchmarks

Latest change:

  • fixed core freeze when load route function didn't bind. #3
  • Plugin manager system added to core. (Document will update soon - 2024/10/24)

Installation

Install Axon.js with npm

  npm install @mr-mkz/axon

Benchmarks

You can checkout Axon benchmarks document and results from below link.

Axon Benchmarks

Badges

Features

  • Simple routing system
  • Support methods: GET, POST, PUT, PATCH, DELETE, OPTIONS.
  • Flexible routing system. (You can define routes in another files and then add them to core)
  • Default core logger
  • Configurable core
  • Plugin manager (You can create your own plugins and use them in other projects)
  • Controllers and Middlewares
  • Default cors configuration method

More features soon...

Roadmap (still thinking)

  • Support controllers better than now.
  • Some changes in response structure.
  • Response meta generator.
  • Auto error detector (maybe)
  • Default schemas.
  • Default database connection methods.

Documentation

Currently Axon has a main core and a router class which you can make instance from router class every where you want and then gave the router instance to core to load routes.

More complete examples:

Router

Router is stil under constructing and it's not a stable version yet but currently it support this methods:

  • GET
  • POST
  • PUT
  • PATCH
  • DELETE
  • OPTIONS

You can access and create routes with just a few steps.

  1. creating a variable with a optional name and put Router() function in it.
  2. define your routes with methods which you want and controller.
    •   const router = Router()
      
        router.get(path, controller(req, res))
  3. load your routes in core with loadRoute() function;
    •   const core = Axon(); // easier and newer method
        // or
        // const core = new AxonCore();
      
        core.loadRoute(router)
  4. Done, you created your routes successfully :D

Controller

you have to pass your controller to your route, compute and do your jobs in controller and when you want to response to user (each response, error and success) you must return res with some options which example and description for each option is below.

res.{option}

Options:

  • status: This option must set to get access to other options. (you can use each option just once)
  • message: This option will set the response message for example response message of status 200 is OK.
  • setHeader: You can set header with this option and also you can use this option many times.
  • body: This option will end request and send response to user so you must use this as last option

Example:

const controller = async (req, res) => {
    return res.status(200).body({
        message: "Hello, World"
    })
}

Middleware

middleware is a function which runs before running controller for validations or some actions like this and you can use it in two ways.

  1. adding a middleware for special route
    • Example:
          router.get('/', controller).middleware(async (req, res, next) => next());
      you can also use multiple middlewares for a route by repeating middleware function and middlewares will run in order.
  2. loading middleware as a global middleware in Axon core.
    • Example:
          core.globalMiddleware(async (req, res, next) => next());
      you can also use multiple middlewares in this way by adding middleware functions into an array (suggested method) or repeating this line of code.

Types

AxonJs has some types which can help you in developing your applications for auto suggestions of your code editor.

Types detect automatically in Typescript but you need to set types for IDE suggestions in Javascript (Javascript Example).

  • AxonCoreConfig: Type of core config object for configuration Axon core as you want.
  • AxonResponseMessage: Type of core config option RESPONSE_MESSAGES.
  • AxonCorsConfig: Type of core config option CORS.
  • Request: Type of controller request param. (IncomingMessage)
  • Response: Type of controller response param. (ServerResponse)
  • Headers: Type of response headers. (OutgoingHeaders)
  • nextFn: Type of next function param in middleware.
  • Controller: Type of controller function.
  • Middleware: Type of middleware function.

Axon Core config

you can config Axon core with loadConfig method. if you want to have ide suggestions for core config use AxonCoreConfig type.

Usage:

core.loadConfig({
    LOGGER: false
})

Configs:

  • DEBUG: boolean to set debug mode of core. (default false)
  • LOGGER: boolean to set core logger on or off. (default true)
  • LOGGER_VERBOSE: boolean to set core logger in verbose mode. (default false)
  • RESPONSE_MESSAGES: object to change default value of some core responses. (type: AxonResponseMessage)
  • CORS: object to change core cors settings. (type: AxonCorsConfig)

Running server

listen method runs your webserver.

core.listen() has some default values

  1. host: default value of host in 127.0.0.1
  2. port: default value of port is 8000
  3. callback: if you don't set callback function, core will log running message automatically if logger be on in core config.(logger is on in default config)
core.listen("0.0.0.0", 80, () => {
    console.log("server is running on port 80")
});

Contributing

Contributions are always welcome!

Authors