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

daf

v0.0.19

Published

Dependency-aware FaaSifier for NodeJS monoliths

Downloads

7

Readme

DAF allows you to outsource parts of a NodeJS app to FaaS

In addition to existing tools, it supports:

  • Dependencies: (install)
  • Importing other files and functions (require)
  • Global variables (vars)

Install

npm i -g daf # install globally

Usage

Add annotations in your Monolith code:

// l     
var a = 1;
// lend 

Run DAF via Terminal (Not recommended):

$ daf OPTIONS... 

Options:

  • --fpath PATH: The path to the .js file in which you want to faasify code
  • --linenum NUM: The line number of the // l ... Annotation. Beware, it's 0-indexed.
  • --outpath PATH: The path where the generated FaaS functions will be put (outpath/lambdas/...).
  • [--commentout]: If specified, the faasified section will be replaced with an Lambda API call. Don't forget to specify //l name(...)!

Run DAF via Editor Extension:

Upcoming: https://github.com/qngapparat/daf-vscode

Output

The tool creates an equivalent Lambda function of that section in [--output]/lambdas/[name]:

└── lambdas
    └── 28723n2398jfs9f87239uhfe9
        ├── index.js
        └── package.json 

You can deploy this function directly to AWS Lambda. One file can have multiple // l ... // lend sections, that can be converted separately.

Annotations

//l can be followed by any combination of these space-separated directives.

name

You can give your Lambda a name to better keep track of it:

// l name(mylamb)
 var a = 1
// lend
└── lambdas
    └── mylamb
       └── ....
    

vars

Your code might rely on global variables. You can denote them with vars():

var a = 1
// l vars(a)
a++
// lend

They will be added to the scope inside the Lambda.

require

Your code might rely on functions from other files. You can declare that using require():

// l require(./foo.js as foo)
foo()
// lend

A portable version of foo.js is then included in the deployment package, and it is added to the scope inside the Lambda.

└── lambdas
    └── myfunc
       └── foo.js  // <---
       └── ...

If foo in turn depends on other functions or dependencies, they are bundled as well (recursively) using webpack.

install

Your code might depend on NPM packages. You can specify them with install(). They will be included in your deployment package.

// l install(opencv2)
....
// lend

You probably want to import it as well:

// l install(opencv2) require(opencv2)
   opencv2.detectFaces(...)
// lend

return

Your monolith code may have no return statement. To receive something back from the lambda, use return()

// l return(a)  
  var a = 1
  var b = 2
// lend

Useful hints

Multiple parameters

With most // l expressions, you can provide a comma-separated list too:

// l vars(a, b, c)
...

Aliasing

You can rename functions and packages, when import them:

// l require(opencv2 as cv)
  cv.detectFaces(...)
// lend

This is obligatory if you import local functions.

Versioning

You can specify the exact versions of the NPM packages to install:

// l install(pkg1@latest, pkg2^1.0.0, pkg3>=1.2.3)
...
// lend

The syntax follows this official schema: https://docs.npmjs.com/misc/semver