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

functioneer-express

v1.0.0

Published

Express helpers for functioneer.

Downloads

1

Readme

Functioneer-express

Helper functions for Functioneer - for use with Express framework.

Installation

Run npm install i functioneer-express and import to your project.

Usage

Declare a function:

import {Functioneer} from "functioneer";
import { getExpressHandler} from "functioneer-express";
const func = new Functioneer();
//Declare a function to add two numbers
func.registerFunction("add", "Adds two numbers", (a: number, b: number) => {
    return a + b;
})
.addField("a", "number", "The first number to add")
.addField("b", "number", "The second number to add");

Use the express handler for a path

const app = express();
app.post("/functions", getExpressHandler(func, "BODY");
await app.listen(8080);

Exposed methods

Both methods exposed by functioneer-express run a declared function based on request parameters: getExpressHandler(functioneerInstance,dataSource,functionName?) getExpressMiddleware(functioneerInstance,dataSource,functionName?)

| arguement | type | | | ------------------- | ----------- | ------------------------------------------------------------------------------------- | -------- | -------- | | functioneerInstance | Functioneer | An instance of Functioneer | | dataSource | string | Where to get the function arguements from ("BODY" | "PARAMS" | "QUERY") | | functionName | string? | The function to be called. If null then select the function name from the data source |

The behavior after running the exposed methods is different: | method | | |--------|--------| | getExpressHandler | Runs function and retuns result to client as request body with 200 status | | getExpressMiddleware | Runs a function and stores the result in request.functionResult. When function execution execution of the middleware stack continues

Dynamic function selection

As mentioned before you can either hardcode the function to run or parse it through the dataSource:

const func = new Functioneer();
func.registerFunction("add", "Adds two numbers", (a: number, b: number) => { return a + b; }).
addField("a", "number", "The first number to add").
addField("b", "number", "The second number to add");

const app = express();
// This will run the add function
app.post("/functionsAdd", getExpressHandler(func,"BODY","add"));

// This will run any function specified in request.body.functionName
app.post("/functionsAll", getExpressHandler(func,"BODY"));

Data sources

The following data sources are supported:

| Data source | value | | | -------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Request body | "BODY" | JSON data from request body | | URL parameters | "PARAMS" | URL parameters as set up in express. For example : app.post("/functionsAdd/:a/:b",getExpressHandler(func,"PARAMS","add")); | | Query string | "QUERY" | Query string parameters as set by client. For example a request to /functionsAdd?a=1&b=2 will match app.get("/funtionsAdd",getExpressHandler(func,"QUERY","add")) |

Building and testing

You can build the project by running npm run build. Tests are run by running npm run test

License

Functioneer-express is licensed under MIT license