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

aureolin

v1.0.0

Published

Rest API Framework

Downloads

14

Readme

Aureolin

Aureolin is a simple, fast, and powerful MVC framework for Node.js with a focus on simplicity and performance. Built With Koa

NPM FOSSA Status

NPM Discord CodeFactor NPMPrettier


Installation

npm install aureolin

Getting Started

To get started with Aureolin, you need to create a config file named aureolin.config.js in the root of your project.

/** @filename aureolin.config.js */

const { join } = require('path')

/** @type {import('aureolin').Config} */
module.exports = {
    root: join(process.cwd(), process.env.NODE_ENV === 'production' ? 'dist' : 'src')
    port: 4000,
    public: {
        path: '/public',
        dir: './public',
        index: 'index.html'
    },
    views: {
        path: 'views',
        extension: 'hbs',
        map: { 
            hbs: 'handlebars' 
        }
    }
}

Then, use the create function to create the app.

/** @filename src/main.ts */

import { create } from 'aureolin'
// import create from 'aureolin'
// const { create } from require('aureolin')

const main = async () => {
    const app = await create()
}

Controllers

To create a controller you need to import the Controller decorator from Aureolin.

Decorators for all Http methods are provided

The return value of the methods prefixed with an Http Decorator in a controller are sent as the response Response can be a string, number, object, array, or even a JSX Element (YES! JSX See Here)

Use the provided Parameter Decorators to let Aureolin to know what parameters pass to the to the controller methods.

/** @filename src/controllers/hello.tsx */
import { Controller, Context, Get, Ctx, Param } from 'aureolin'

@Controller('/hello')
export class HelloController {
    @Get('/')
    async hello() {
        return (
            <div>
                <h1>Hello World!</h1>
                <p>This is a simple example of Aureolin</p>
            </div>
        )
    }

    @Get('/:name')
    async helloName(@Ctx() { params: { name } }: Context) {
        return `Hello ${name}!`
    }

    @Get('/:name/:age')
    async helloNameAge(@Param('name') name: string, @Param('age') age: string) {
        return `Hello ${name}! You are Probably ${age} years old.`
    }    
}

Providers

Providers are a way to inject dependencies into your controllers. Use the provider decorator to decalre a class as a provider. Use the inject decorator to inject provider into your controllers.

@Provider(provide: string)

/** @filename src/providers/time.ts */
import { Provider } from 'aureolin'

@Provider('time')
export default class TimeProvider {
    async getTime() {
        return new Date().toLocaleTimeString()
    }
}

@Inject(provide: string)

/** @filename src/controllers/time.ts */
import { Controller, Context, Get, Inject } from 'aureolin'
import type TimeProvider from 'providers/time.ts'

@Controller('/time')
export class TimeController {

    constructor(@Inject('time') private timeProvider: TimeProvider) {}

    @Get('/')
    async getTime() {
        return timeProvider.getTime()
    }
}

Middlewares

Use the @Middleware and @ControllerMiddleware Decorator factories

import { Middleware, Controller, ControllerMiddleware, Context, Get, Ctx, Param, NextFunction } from 'aureolin'

@Contoller('cakes')
@ContollerMiddleware([
    (ctx: Context, next: Next) => {
        console.log('Controller Middleware 1')
        return next()
    }
])
export default class CakesController {

    @Get('/cheesecake')
    @Middleware([cheesecakemiddleware])
    public cheesecake() {
        return {
            name: 'Cheesecake',
            ingredients: ['cheese', 'flour', 'sugar']
        }
    }

    @Get('/redvelvet')
    @Middleware([redvelvetmiddleware])
    public redvelvel() {
        return {
            name: 'Red Velvet',
            ingredients: ['cheese', 'flour', 'sugar', 'red stuff']
        }
    }
}

Error Handling

Aureolin takes care of error handling for you. Use the exported Exception or Prebuilt classes to throw error dircetly in your code and aureolin will handle it.

/** @filename src/controllers/error.ts */
import { Controller, Context, Get, Exception, BadRequestException } from 'aureolin'

@Controller('/error')
export class ErrorController {
    @Get('/')
    async error(): never {
        throw new Exception('Something went wrong!', 500)
    }

    @Get('/:name')
    async errorName(@Ctx() { params: { name } }: Context): never {
        if (!name) throw new BadRequestException(`${name} is not a valid name!`)
    }
}

And finally you can call create() to start your app.

/** @filename src/main.ts */

import { create } from 'aureolin'
const main = async () => {
    const app = await create()
}

main()

After you have created the application, Visit http://localhost:3000/hello to see the output of the hello controller.

Check out the Docs Folder for more information.

Key Features

  • Decorator based routing
  • Highly configurable & scalable
  • Server Side Rendering
  • Strongly Typed

Contributing


Thank you for using Aureolin!

License

FOSSA Status