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 🙏

© 2026 – Pkg Stats / Ryan Hefner

m2faas

v1.0.5

Published

Monolith to FaaS

Readme

Prerequisite

  • Installed and configured AWS CLI and ÌBM CLI.
  • Node.js version >= 10.2.0

Install

npm i m2faas -g

Usage

1. Add annotations to the monolith

Enclose your code block with annotations:

//cfun ...
    <code_block>
//cfunend

2. Run M2FaaS

m2faas example/

3. Run the generated monolith

cd out && npm install
node your_code.js

Annotations

Include external package(s): require

//cfun require(./foo.js as foo,lodash as _)
const fooBefore = foo.fun(12);
const value = _.chunk(['a', 'b', 'c', 'd'], 2);
// cfunend

Install external NPM package(s): install

//cfun install(lodash)
const value = _.chunk(['a', 'b', 'c', 'd'], 2);
// cfunend

Make variable(s) accessible after function call: assign

let value1 = 5;
//cfun assign(value1,value2)
value1 = 12;
const value2 = 34;
// cfunend
const sum = value1 + value2;

Value declared outside of the function scope: vars

let value1 = 2;
//cfun vars(value1)
value1 = 12;
// cfunend

Deployment details of the cloud function(s): deploy

deploy allows to specify an ordered list of deployments. All of the specified configurations will be deployed.

This annotation also specifies the fault tolerance of the execution. If the cloud function call to the first function fails, the next cloud function in the list will be invoked.

The deployment configuration is represented as a json-array:

[
  {
    "name": "m2FaaSExampleAWS",                       
    "provider": "aws",                                
    "region": "us-east-1",                           
    "memorySize": 128,                           
    "runtime": "nodejs14.x",                        
    "timeout": 3,                                   
    "role": "arn:aws:iam::xxxxxxxxxxx:role/service-role/xxxxxxx"
  },
  {
    "name": "m2FaaSExampleIBM",                       
    "provider": "ibm",                                
    "region": "eu-gb",
    "memorySize": 128,
    "runtime": "nodejs:12", 
    "timeout": 60
  }
]

region, memorySize, runtime, timeout represents optional values. If no specified, default values will be used.

//cfun deploy([{"name": "m2FaaSExampleAWS", "provider": "aws", "region": "us-east-1", "memorySize": 128, "runtime": "nodejs14.x", "timeout": 3, "role": "arn:aws:iam::170392512081:role/service-role/getFlight-role-n1g2o34s"},{"name": "m2FaaSExampleIBM", "provider": "ibm", "region": "eu-gb", "memorySize": 128, "runtime": "nodejs:12", "timeout": 60 }])
...
// cfunend

Example

The example monolithic project consists of three files:

  • package.json contains the dependencies of the monolithic application.
  • foo.js contains a a simple nodeJs function.
  • example.js is the starting point of the application:

example.js:

const foo = require('./foo')
const _ = require('lodash')

async function main(args) {
   let a = 2;

    // cfun require(./foo.js as foo,lodash as _) assign(value,a,foo1) vars(a) install(lodash) deploy([{"name": "m2FaaSExampleAWS", "provider": "aws", "region": "us-east-1", "memorySize": 128, "runtime": "nodejs14.x", "timeout": 3, "role": "arn:aws:iam::170392512081:role/service-role/getFlight-role-n1g2o34s"},{"name": "m2FaaSExampleIBM", "provider": "ibm", "region": "eu-gb", "memorySize": 128, "runtime": "nodejs:12", "timeout": 60 }])
    await new Promise(resolve => setTimeout(resolve, 5000));
    const foo1 = foo.fun(a);
    a = 43;
    const value = _.chunk(['a', 'b', 'c', 'd'], 2);
    // cfunend

    return { a: a, value: value, foo1: foo1, foo2: foo.fun(a) }
}

main().then(response => { console.log(response) });

The annotated code has the following specialities:

  • The code block, which should be FaaSified, has two external dependencies: ./foo.js represents a local code dependency, while lodash represents an external package dependency.
  • After the FaaSification the variables value, a and foo1 need to be available.
  • The variable a is not declared in the code block and therefore an input to the cloud function.

The tool generates a foo.js file to solve the local dependency and a package.json for the external dependency.

AWS Lambda Function

The generated lambda function:

const foo = require("./foo.js")
const _ = require("lodash")

exports.handler = async (event) => {
  let a = event.a

  // cfun require(./foo.js as foo,lodash as _) assign(value,a,foo1) vars(a) install(lodash) deploy([{"name": "m2FaaSExampleAWS", "provider": "aws", "region": "us-east-1", "memorySize": 128, "runtime": "nodejs14.x", "timeout": 3, "role": "arn:aws:iam::170392512081:role/service-role/getFlight-role-n1g2o34s"},{"name": "m2FaaSExampleIBM", "provider": "ibm", "region": "eu-gb", "memorySize": 128, "runtime": "nodejs:12", "timeout": 60 }])
  await new Promise((resolve) => setTimeout(resolve, 5000))
  const foo1 = foo.fun(a)
  a = 43
  const value = _.chunk(["a", "b", "c", "d"], 2)

  return (response = {
    statusCode: 200,
    body: { value: value, a: a, foo1: foo1 },
  })
}
IBM Cloud Function

Starting point of the IBM function:

const foo = require("./foo.js")
const _ = require("lodash")

async function main(event) {
  let a = event.a

  // cfun require(./foo.js as foo,lodash as _) assign(value,a,foo1) vars(a) install(lodash) deploy([{"name": "m2FaaSExampleAWS", "provider": "aws", "region": "us-east-1", "memorySize": 128, "runtime": "nodejs14.x", "timeout": 3, "role": "arn:aws:iam::170392512081:role/service-role/getFlight-role-n1g2o34s"},{"name": "m2FaaSExampleIBM", "provider": "ibm", "region": "eu-gb", "memorySize": 128, "runtime": "nodejs:12", "timeout": 60 }])
  await new Promise((resolve) => setTimeout(resolve, 5000))
  const foo1 = foo.fun(a)
  a = 43
  const value = _.chunk(["a", "b", "c", "d"], 2)

  return { value: value, a: a, foo1: foo1 }
}
exports.main = main
Adapted Monolith

The code block is replaced by a cloud function call:

const foo = require('./foo')
const _ = require('lodash')

async function main(args) {
   let a = 2;

    // cfun require(./foo.js as foo,lodash as _) assign(value,a,foo1) vars(a) install(lodash) deploy([{"name": "m2FaaSExampleAWS", "provider": "aws", "region": "us-east-1", "memorySize": 128, "runtime": "nodejs14.x", "timeout": 3, "role": "arn:aws:iam::170392512081:role/service-role/getFlight-role-n1g2o34s"},{"name": "m2FaaSExampleIBM", "provider": "ibm", "region": "eu-gb", "memorySize": 128, "runtime": "nodejs:12", "timeout": 60 }])
    /* await new Promise(resolve => setTimeout(resolve, 5000));
    const foo1 = foo.fun(a);
    a = 43;
    const value = _.chunk(['a', 'b', 'c', 'd'], 2); */
    // cfunend
    
    try {
        m2FaaSExampleIBMResult = await require('./m2faaSInvoker').invoke({ a: a,  }, [{"name":"m2FaaSExampleAWS","provider":"aws","region":"us-east-1"},{"name":"m2FaaSExampleIBM","provider":"ibm","region":"eu-gb"}]);
    } catch (e) {
        m2FaaSExampleIBMResult = await async function() {     // cfun require(./foo.js as foo,lodash as _) assign(value,a,foo1) vars(a) install(lodash) deploy([{"name": "m2FaaSExampleAWS", "provider": "aws", "region": "us-east-1", "memorySize": 128, "runtime": "nodejs14.x", "timeout": 3, "role": "arn:aws:iam::170392512081:role/service-role/getFlight-role-n1g2o34s"},{"name": "m2FaaSExampleIBM", "provider": "ibm", "region": "eu-gb", "memorySize": 128, "runtime": "nodejs:12", "timeout": 60 }])
            
            await new Promise(resolve => setTimeout(resolve, 5000));
            const foo1 = foo.fun(a);
            a = 43;
            const value = _.chunk(['a', 'b', 'c', 'd'], 2);
            
            return { value: value, a: a, foo1: foo1,  } 
         }(); 
    } 
    value = m2FaaSExampleIBMResult.value
    a = m2FaaSExampleIBMResult.a
    foo1 = m2FaaSExampleIBMResult.foo1

    return { a: a, value: value, foo1: foo1, foo2: foo.fun(a) }
}

main().then(response => { console.log(response) });