Skip to content
OpenFaaS Node.js 10 (LTS) and Express.js micro-service template
JavaScript Dockerfile
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
template/node10-express-service Fix Dockerfile Jun 26, 2019
.DEREK.yml Add inital template Jun 4, 2019
.dockerignore Add inital template Jun 4, 2019
.gitignore Add inital template Jun 4, 2019
LICENSE Add inital template Jun 4, 2019
README.md Remove eTag in entrypoint Jun 4, 2019

README.md

OpenFaaS Node.js 10 (LTS) and Express.js micro-service template

This template provides Node.js 10 (LTS) and full access to express.js for building microservices for OpenFaaS, Docker, Knative and Cloud Run.

With this template you can create a new microservice and deploy it to a platform like OpenFaaS for:

  • scale-to-zero
  • horizontal scale-out
  • metrics & logs
  • automated health-checks
  • sane Kubernetes defaults like running as a non-root user

Status of the template

This template is experimental and I would like your feedback through GitHub issues or OpenFaaS Slack.

Supported platforms

  • x86_64 - node10-express-service

Get started

You can create or scaffold a new microservice using the OpenFaaS CLI.

# USERNAME is your Docker Hub account or private Docker registry
$ export USERNAME=alexellisuk

$ faas template pull https://github.com/openfaas-incubator/node10-express-service
$ faas new --lang node10-express-service microservice1 --prefix="${USERNAME}"

Once you've written your code you can run faas-cli build to create a local Docker image, then faas-cli push to transfer it to your registry.

You can now deploy it to OpenFaaS, Knative, Google Cloud Run or even use docker run.

See also: Deploy OpenFaaS

Example usage

Minimal example with one route

"use strict"

module.exports = async (config) => {
    const app = config.app;

    app.get('/', (req, res) => {
        res.send("Hello world");
    });
}

Minimal example with one route and npm package

npm install --save moment
"use strict"

const moment = require('moment');

module.exports = async (config) => {
    const app = config.app;

    app.get('/', (req, res) => {
        res.send(moment());
    });
}

Example usage with multiple routes, middleware and ES6

"use strict"

module.exports = async (config) => {
    const routing = new Routing(config.app);
    routing.configure();
    routing.bind(routing.handle);
}

class Routing {
    constructor(app) {
        this.app = app;
    }

    configure() {
        const bodyParser = require('body-parser')
        this.app.use(bodyParser.json());
        this.app.use(bodyParser.raw());
        this.app.use(bodyParser.text({ type : "text/*" }));
    }

    bind(route) {
        this.app.post('/*', route);
        this.app.get('/*', route);
        this.app.patch('/*', route);
        this.app.put('/*', route);
        this.app.delete('/*', route);
    }

    handle(req, res) {
        res.send(JSON.stringify(req.body));
    }
}

handler.js

You can’t perform that action at this time.