This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

openfaas-node-multiarch
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

OpenFaaS-Node-Multiarch

A multi-arch template for running Node and TypeScript applications on OpenFaaS

This package is purely to provide the TypeScript interfaces for use in the functions.

Compatibility with official Node12 template

This template is designed as a drop-in replacement for the official Node12 template in the OpenFaaS store. It should be considered as an improvement to that template, offering the following:

  • TypeScript support
  • Multi-arch builds (can use the same template to build for your AMD64 laptop and ARM on a Raspberry Pi)
  • Simplified function interface

TypeScript Support

Interfaces are published to npm under the openfaas-node-multiarchpackage.

A tsconfig.json file is included for convenience. However, as TypeScript building is handled by the Docker image, this should only be used for local running.

Simplified Interface

In the official Node12 template, you must return context.succeed(response) to send data outwards. Whilst I have no issue with that in itself, it can make testing a little harder than it needs to be. For that reason, any value returned, resolved or rejected from the function is treated as the response.

There are no performance differences as the methods are just syntactic sugar, allowing personal preference to be the differentiator.

These all result in the same output:

// Successful execution
module.exports = (event, context) => {
  context.httpHeaders = {
    'content-type': 'application/json',
  };
  context.httpStatus = 403

  return { hello: 'world' };
};

module.exports = (event, context) => context
  .headers({
    'content-type': 'application/json',
  })
  .status(403)
  .succeed({ hello: 'world' });
// Failed execution
module.exports = () => {
  throw new Error('some error');
};

module.exports = (event, context) => context
  .fail(new Error('some error'));

Examples

JavaScript

This must be set to handler.js

module.exports = (event, context) => {
  const response = {
    status: `Received input js: ${JSON.stringify(event.body)}`,
  };

  return context
    .status(200)
    .succeed(response);
};

TypeScript

This must be set to tsHandler.ts

import { IFunctionContext, IFunctionEvent } from 'openfaas-node-multiarch';

export default (event: IFunctionEvent, context: IFunctionContext) => {
  const response = {
    status: `Received input: ${JSON.stringify(event.body)}`,
  };

  return context
    .status(200)
    .succeed(response);
};

Package Sidebar

Install

npm i openfaas-node-multiarch

Weekly Downloads

523

Version

1.2.0

License

MIT

Unpacked Size

121 kB

Total Files

18

Last publish

Collaborators

  • npm