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

nodeflare

v1.1.0

Published

A framework built on [Express](https://expressjs.com/) with built in JWT authentication, Dependency Injection, and Eventing.

Downloads

53

Readme

NodeFlare

A framework built on Express with built in JWT authentication, Dependency Injection, and Eventing.

Getting Started

There are only a few steps to getting NodeFlare up and running.

Install

npm install --save nodeflare sequelize sqlite3

Run It!

import {NodeFlare} from 'nodeflare';

let config = {hostname: 'http://localhost', port: 61370, tokenkey: '12345'};
let app = new NodeFlare(config).start();
              
export default app;

Features

By default, NodeFlare starts up as an empty application listening on the port you configured. You can enable additional features prior to calling .start() on the NodeFlare object.

Auth Services

To enable the authentication services you can call .withAuthServices()

let app = new NodeFlare(config)
              .withAuthServices()
              .start();

App Settings

You can configure application settings with .appSet(setting, value). You can set existing Express Settings

let app = new NodeFlare(config)
              .appSet('view engine', 'pug')
              .start();

Middleware

You can pass an optional path and function to .appUse(path, function) to add middleware to your application. You can pass in a Router as a function. This will allow you to more easily encapsulate Routers into their own classes.

import {NodeFlare, Router} from 'nodeflare';

let router = new Router();
router.get('/fun', (req, res, next) => {
  res.json({message: 'Yay'});
});

let app = new NodeFlare(config)
              .appUse('/api', router)
              .start();

This will create path /api/fun and will execute the router function.

If you turn on the Authentication Services, by default all new services you create are protected and you must preset a valid auth token. If you wish to allow (whitelist) certain services, you can call .whitelist(string|array).

let app = new NodeFlare(config)
              .withAuthServices()
              .whitelist('/custom/url')
              .start();

Dependency Injection

When you call start on a NodeFlare object, this creates the Application Context. This is available as global.ctx. You can register your own classes prior to calling start().

let app = new NodeFlare(config)
              .register('Name', '<Class>')
              .register('Name', '<Class>', ['<Constructor Args>'])
              .start();
let app = new NodeFlare(config)
              .registerInstance('Name', '<Object Instance>')
              .start();
let app = new NodeFlare(config)
              .registerAndUse('/custom/url', 'Name', '<Class>', '[Constructor args]')
              .registerAndUse('/custom/url', 'Name', '<Class>')
              .start();

Onces you have started your application, you can call ctx.get('Name') to get the instance of the class you registered.

Event Hub

You can get a reference to the EventHub from the application context

let eventHub = ctx.get('EventHub');

Subscriptions

You can subscribe to events with the key and channel and provide an event handler. Currently only unsubscribing from a key is supported.

let eventHub = ctx.get('EventHub');

eventHub.subscribe(SomeClassName, 'Updated', (data) => {
  console.log(data);
});

eventHub.unsubscribe(SomeClassName);

Publish

You can publish events to any channel.

let eventHub = ctx.get('EventHub');

eventHub.publish('Updated', {}); // Channel & Payload. Payload is optional

Configuration

Below is the configuration that is available. The following properties are required, everything else is optional depending on your environment.

  • hostname
  • port
  • tokenkey
{
	"hostname": "http://localhost:61370",
	"port": 61370,
	"tokenkey": "<Some Random>",
	"passwordresettoken": "<Some Random>",
  "database": {
    "type": "<pg|mysql|sqlite>", 
    "db": "<Database Name>", 
    "path": "<File path for Sqlite. Empty for in memory>", 
    "host": "<Hostname for mysql/postgres>", 
    "user": "<DB User for mysql/postgres>", 
    "password": "<DB Password for mysql/postgres>"
  },
  "mail": {
    "disabled": true,
    "api": "<Api Url for Mail Gun>",
    "from": "",
    "message": "<Message for the Password Reset Email>",
    "subject": "<Password Reset Email Subject>"
  }
}

Database

NodeFlare uses Sqlite by default to store users. Through configuration you can specify PostgreSQL or MySQL which are both supported.

Built in User & Authentication Services

Authentication Service

/auth/login -> Method: Post

Request Object

{
  "username": "<User Account Email Address>",
  "password": "<Account Password>"
}

Json Response

{"token": "<Authentication Token>", "sessionData": "<Custom Session Data Object>"}

/auth/passwordreset -> Method: Post

Request Object

{
  "emailAddress": "<User Account Email Address>",
  "passwordresettoken": "<Token that was provided through configuration>"
}

Json Response

{"token": "<Request Token>", "emailAddress": "<Account Email Address>"}

The My Service

/my/user -> Method: Get

Json Response

{
  "id": "user.id",
  "version": "user.version",
  "emailAddress": "user.emailAddress"
}

In addition to the above properties, all the properties you specify in the details of the create will be included.

/my/user/create -> Method: Post

Request Object

{
  "emailAddress": "<Email>",
  "password": "<Password>",
  "details": {} // any data you want stored with the user as an object
}

Json Response

/my/user/edit -> Method: Post

Request Object

{
  "id": "<ID>",
  "version": "<VERSION>",
  "emailAddress": "<Email>",
  "details": {} // User object you want to edit.
}

Json Response

Who do I talk to?

Contact [email protected]