0.2.18 • Published 1 year ago

express-integrator-extension v0.2.18

Weekly downloads
51
License
MIT
Repository
github
Last release
1 year ago

express-integrator-extension

js-standard-style

This module extends integrator-extension and can be used to create an express app which exposes an API that is used by integrator.io to invoke the extension functions and get back the results. This extension type is based on the stack of type server in integrator.io. The baseURI for the API will be same as the hostURI of the stack and stack's systemToken is used to authenticate the requests made to the API. You can host the express app on a single server or a set of servers behind a load balancer to scale as needed.

Installation

Using npm:

$ npm i --save express-integrator-extension

Usage

var expressExtension = require('express-integrator-extension')

expressExtension.createServer(config, function (err) {

})

expressExtension.stopServer(function (err) {

})

createServer(config, callback)

createServer function loads the configuration and starts an express app. Given below are the configuration fields that can be set along with the fields mentioned in integrator-extension configuration.

port

Optional. This field specifies the port that should be used by the express server. Default port is 80.

systemToken

Required. This needs to be set to the stack's systemToken that you created in integrator.io.

maxSockets

Optional. This field is to customize the value for https.globalAgent.maxSockets. Default value is set to Infinity.

winstonInstance

Optional. This field is used to pass the winston instance which will be used to log information. By default logs go only to the console output.

stopServer(callback)

stopServer function stops the express app from listening on the designated port.

Getting Started

Given below are the complete steps to create a working Express based stack.

  1. Create a stack in integrator.io
  2. Login into integrator.io.
  3. Click on options field present at the top right corner and select stacks.
  4. Click on the New Stack button.
  5. Give an appropriate name for the stack.
  6. Select type as "Server".
  7. Set the "Host" field to the URI on which the project will be hosted on. Don't worry if the URI is not available at this time. You can come back and update the stack later!
  8. Click save to create the stack.
  9. You will be redirected to the stacks page. Please make note of the System Token by clicking on "click to display" under the System Token column corresponding to the stack which you have created.

  10. Write code

  11. Run "npm init" to create node project in a new folder.
  12. Run "npm i --save express-integrator-extension".
  13. Create a new file functions.js and save the following extension functions in it.

      var obj = {
        hooks: {
          preSaveFunction: function (options, callback) {
            // your code
          }       
        },
    
        wrappers: {
          pingFunction: function (options, callback) {
            // your code
          }
        }
      };
    
      module.exports = obj;
  14. Create a new file index.js and save the following code in it. Either the DIY or connectors configuration should be used.

    var expressExtension = require('express-integrator-extension');
    var functions = require('./functions');
    
    var systemToken = '************'; // Set this value to the systemToken of the stack created in integrator.io
    var options = {
      diy: functions,
      // connectors: { _connectorId: functions }, // for connectors
      systemToken: systemToken
    };
    
    expressExtension.createServer(options, function (err) {
    
    });
  15. Host the node project on a single server or a set of servers behind a load balancer to scale as needed. Any server based hosting environment like AWS EC2, AWS Opsworks, Rackspace Cloud, Google Cloud, Heroku, etc. can be used to run the code. Update the stack in integrator.io with the endpoint URI of your server or load balancer.

Now, the stack is ready for use and it can be referenced from appropriate exports, imports and connections. To maintain security, systemToken should be stored securely on your server environment. Please refer to best practices of the respective system that you chose to run the express app.

0.2.18

1 year ago

0.2.17

1 year ago

0.2.16

1 year ago

0.2.15

1 year ago

0.2.14

1 year ago

0.2.13

2 years ago

0.2.12

2 years ago

0.2.11

4 years ago

0.2.10

4 years ago

0.2.9

4 years ago

0.2.8

4 years ago

0.2.7

4 years ago

0.2.5

5 years ago

0.2.4

5 years ago

0.2.3

7 years ago

0.2.2

7 years ago

0.2.1

7 years ago

0.2.0

8 years ago

0.1.6

8 years ago

0.1.5

8 years ago

0.1.4

8 years ago

0.1.3

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago