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

acrus

v2.0.1

Published

An efficient ExpressJs framework for creating awesome web servers

Downloads

4

Readme

Acrus

An efficient ExpressJs framework for creating awesome web servers

Table of Content

  1. Introduction
  2. Getting Started
  3. Credits

Introduction

This frameworks aims to have web servers built in an object oriented programming (OOP) way, and organise structure of API. Enjoy using ExpressJs like you didn't do before, with all utilities and features this framework provides.

Getting Started

Download the package using

$ yarn add acrus
# or
$ npm install acrus

You first need to create a server instance, providing valid options.

Inside index.js, require acrus, extend the Server class and provide desired options to super.

const { Server } = require('acrus');

class MyServer extends Server {
	constructor() {
		super({
			port: 5000,
			baseEndpoint: '/app'
		});

		// ... extending the class
	}
}

Secondly, you need to create a RouteHandler instance, providing the valid options, and adding it as a property in MyServer#routeHandler.

Constructor of RouteHandler expects a Server instance as first parameter, and RouteHandlerOptions as second one.

After creating a RouteHandler instance, you need to load all routes, and initialise it. Simply call RouteHandler#loadAll and RouteHandler#init. We can do this in a separate method MyServer#_init.

For organising purposes. Define another method MyServer#start that will call the initialise function and listen to the port provided in the options.

const { RouteHandler, Server } = require('acrus');
const { join } = require('path');

class MyServer extends Server {
	constructor() {
		super({
			port: 5000,
			baseEndpoint: '/app'
		});

		this.routeHandler = new RouteHandler(this, {
			directory: join(__dirname, 'routes/')
		});
	}

	_init() {
		this.routeHandler.loadAll();
		this.routeHandler.init();
	}

	start() {
		this._init();
		this.listen();
	}
}

You can then create an instance of your custom server (MyServer), and start it. You can use the event ready to know when the server has started.

const server = new MyServer();

server.on('ready', () => {
	console.log(`Server started on port ${server.port}`);
	console.log(`Modules loaded: ${server.routeHandler.modules.size}`);
});

server.start();

Next step is creating routes. Create a folder, called "routes", and create your first route inside it, "TestGET", for example. You need to extend the class Route and export it.

const { Route } = require('acrus');

class TestGET extends Route {
	constructor() {
		super('test', {
			endpoint: '/test',
			type: 'GET'
		});
	}

	exec(req, res) {
		res.json({ msg: 'hello world' });
	}
}

module.exports = TestGET;

Now run the code, and hit the endpoint you just created, considering the baseEndpoint provided and the endpoint in the route, the URL should be localhost:5000/app/test.

Congratulations, you now have your first web server using Acrus up and running.

Credits

This package is authored and maintained with <3 by GamesProSeif