Installed Service
A summary of how to use the Service Node within a Flow.
Adding a Service Node

Overview

Buildable's Service Nodes are built-in cloud functions that provide a powerful way to add custom asynchronous logic to your Flows. You can use Service functions to interface with your installed Services. Buildable functions support Javascript (ES7) and provide access to select npm modules.
Service Nodes do not have access to the external network. If you need access to the external network, simply use a Request Node.
In this section, we'll go over the following short concepts:

Defining input in a Service Node

When you double click a function node, the code editor will open with 2 tabs. The focused tab is the input tab that allows you to select data that will be passed to your run function. Read more about selecting the input passed into the run function in the "What makes up a node?" section of the "Add Nodes to a Flow" page.

Writing code in a Service Node

Navigate to the run function tab in the code editor to begin writing your code. You can write your custom code in the run function, which accepts any valid Javascript (ES7). The values defined in the input function would be passed as an object named input.
Below is an example function that demonstrates how to interface with an installed Sendgrid service to send an email.
Input
Run
Output
1
/**
2
* Lets you select the input for your node
3
*
4
* @param {Params} params
5
* @param {Object} $trigger - This flow's request object
6
* @param {Object} $nodes - Data from above nodes
7
*/
8
const nodeInput = ({ $trigger, $nodes }) => {
9
return {
10
fromEmail: "[email protected]",
11
toEmail: "[email protected]",
12
subject: "Again, next week?",
13
body: "That jog was a great idea today. Same time next week?"
14
}
15
}
Copied!
1
const { call } = require('@buildable/core');
2
​
3
/**
4
* Lets you asynchronously interact with internal services
5
* Does not have access to external networks
6
*
7
* @param {Run} input
8
*/
9
const run = async (input) => {
10
const response = await call.service("new-sendgrid-d8hf48", "mail", "send", {
11
fromEmail: input.fromEmail,
12
to: input.toEmail,
13
subject: input.subject,
14
text: input.body,
15
});
16
​
17
return response;
18
}
Copied!
1
{
2
"data": [
3
{
4
"statusCode": 202,
5
"body": "",
6
"headers": {
7
"server": "nginx",
8
"date": "Wed, 24 Nov 2021 22:01:23 GMT",
9
"content-length": "0",
10
"connection": "close",
11
"x-message-id": "b5fOsChARaGlG48GArWJSg",
12
"access-control-allow-origin": "<https://sendgrid.api-docs.io>",
13
"access-control-allow-methods": "POST",
14
"access-control-allow-headers": "Authorization, Content-Type, On-behalf-of, x-sg-elas-acl",
15
"access-control-max-age": "600",
16
"x-no-cors-reason": "<https://sendgrid.com/docs/Classroom/Basics/API/cors.html>",
17
"strict-transport-security": "max-age=600; includeSubDomains"
18
}
19
},
20
""
21
]
22
}
Copied!
Service Nodes do not have access to setTimeout, setInterval, setImmediate, queueMicrotask, and eval.

Using NPM Packages in a Service Node

Buildable provides access to certain npm packages that can be used within functions. Access to the axios and got packages are only available in the Request Node.
Here's an example of how you can use the uuid npm package to generate a UUID and create a record in a database for a book.
Input
Run
Output
1
/**
2
* Lets you select the input for your node
3
*
4
* @param {Params} params
5
* @param {Object} $trigger - This flow's request object
6
* @param {Object} $nodes - Data from above nodes
7
*/
8
const nodeInput = ({ $trigger, $nodes }) => {
9
return {
10
name: "Crime and Punishment",
11
author: "Fyodor Dostoevsky"
12
}
13
}
Copied!
1
const { call } = require('@buildable/core');
2
const uuid = require('uuid');
3
​
4
/**
5
* Lets you asynchronously interact with internal services
6
* Does not have access to external networks
7
*
8
* @param {Run} input
9
*/
10
const run = async (input) => {
11
const response = await call.service("my-mongo-5454c8", "books", "create", {
12
uuid: uuid.v4(),
13
name: input.name,
14
author: input.author
15
});
16
​
17
return response;
18
}
Copied!
1
{
2
"uuid": "dd2fa540-cd1f-4298-b317-fa0de15a19ce",
3
"name": "Crime and Punishment",
4
"author": "Fyodor Dostoevsky",
5
"_id": "619fb1860c054000126356ae"
6
}
Copied!
Service Nodes do not have access to the axios and got npm packages.
You can see a full list of all the NPM packages in the Javascript Libraries Catalog. If you don't see the module that you're looking for, let us know and we can usually add it for you.

Throwing errors in a Service Node

If your function throws any form of error, whether syntax or otherwise, the error will be caught in the $nodeErrors object. You can read more about that in the Test a Flow page. You can throw errors as expected by using throw new Error().
Last modified 1mo ago