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

refractile

v0.1.1

Published

Polyglossic middleware for express

Downloads

53

Readme

Refractile

Configuration framework for compiling and coordinating polyglossic middleware in Express using WebAssembly.

NPM Version NPM Install Size NPM Downloads

Overview

Refractile: "...capable of refraction"

- Merriam Webster

With Refractile, Node developers gain the ability to refract server-side functionality through the many prisms of other languages. Refractile facilitates the incorporation of WebAssembly modules with diverse sources into the Node runtime environment, specifically targeting the middleware design patterns of Express.

Given that so much of web development has become monoglossic as JavaScript continues its imposing march from the frontend to the backend, with Refractile you can experience a best-of-all-worlds developer experience. You could write functionality that benefits from the speed of C or the affordances of some particular package for Go all while still organizing your server in the lightweight, efficient context of Express JS.

Installation

Make sure you have Node.js installed before you begin.

You can install refractile into your project using the npm.

$ npm install refractile

Core Concepts

The two core concepts to understand when working with this package are its configuration system and the function refract itself.

The function

The interface for refract is simple: it takes two arguments — a reference to a module and a function on that module to be invoked. As an exmaple, this would look as follows:

refract('some_module', 'some_function');

Simple!

refract returns an express middleware function, in other words a function that expects a Request object, a Response object, and a Next function. These are the arguments that will be fed into the function requested on the module, which, in the example above, would be some-funciton.

refract works with WebAssembly under the hood; currently, it requires JavaScript glue code to run. In the example above some_module would be associated with a file called some_module.js that is responsible for instantiating some_module.wasm. The point of this package is to organize the compilation of .wasm files and, in some cases, .js glue code as express middleware.

The configuration

The function refract works with a configuration file called refractile.config.js. For refract to work, you must also create and configure refractile.config.js.

The configuration should look as follows:

module.exports = {
    preload_cmds: [ ] // This is an array of strings representing commands that will run when the configuration is loaded. Use it to create or copy any resources that your modules will depend on

    modules: { // This object contains the unique configurations for each module you want to include

        some_module: { // The name of the module is organized by this key

            bin: "./some_folder", // (Required) The folder where refractile will look for the JS module

            make: " ", // (Required) The command to be evaluated for building sources into WASM modules

            src: " ", // The path to the source code. Refract will use this reference to determine if the module needs to be rebuilt after the code updates.

            gluecode_src: " " // If your compiler does not generate WebAssembly gluecode, you can write your own. When you point to it with this option, it will be copied into the bin folder with a name matching the module key (e.g. some_module) and a .js extension after the .wasm file was compiled.
        },

        // Other modules should be configured similarly
        some_other_module: { ... }
    }
};

Example

You can find a project making use of refractile here.

The example app showcases two ways of working with this package — one where a given WebAssembly compiler generates gluecode and one where custom gluecode is written by the developer and pointed to in the configuration file.

The app itself benchmarks the performance of a recursive algorithm that calculates the nth value of the fibonacci series in Go and C++ against the equivalent implementation in JavaScript

Example dependencies

To run the project, you must have the following dependencies installed:

To run the example

After installing the above dependencies, install node packages by running npm i

Then run the command npm start to build the front-end, compile the WebAssembly modules, and start the server.