Was this helpful?

Which standard Node.js modules are supported?

Use the following table to determine which standard Node.js modules are either supported, not supported, or partially supported in Apigee Edge. 


Module Status Notes
assert Supported  
buffer Supported  
child_process Restricted An exception will be thrown if an attempt is made to spawn a sub-process. However, "fork" is supported for spawning sub-scripts.
cluster Disabled The method cluster.isMaster always returns true, and other methods are not implemented. See Why the cluster module is disabled.
crypto Partial support Random and HMAC functionality is supported. The remainder is unimplemented.
dns Partial support dns.lookup is supported. All else is not implemented.
domain Supported  
dgram Restricted Node.js applications in the Apigee environment will not be able to access services on the Internet via UDP due to our network architecture.
events Supported  
fs Restricted Filesystem access is restricted to the directory where the script was launched: the /resources/node directory. Node.js scripts may read and write files within this directory, for instance as a temporary scratch area, but there are no guarantees as to how long the files will persist.
http Supported The virtual host and path for incoming requests is specified in the API Proxy, not by the HTTP module. See "Understanding support for the http and https modules" for more information.
https Supported Creating an "https" server behaves identically to an "http" server. See "Understanding support for the http and https modules" for more information.
module Supported  
net Restricted Attempts to listen for incoming TCP connections will generate an exception.
path Supported  
module Supported  
process Partial support Functionality to manipulate user ID, group membership, and working directory is not supported.
punycode Supported  
querystring Supported  
readline Disabled There is no standard input for scripts running on Apigee Edge.
repl Disabled There is no standard input for scripts running on Apigee Edge.
module Supported  
STDIO Supported Standard output and error are routed to a log file within the Apigee Edge infrastructure. There is no standard input for scripts running on Apigee Edge. However, you can pass arguments using the ScriptTarget element of TargetEndpoint. See Advanced ScriptTarget configuration  for more information.
stream Supported  
string_decoder Supported  
timers Supported  
tls Supported Transport Layer Security (TLS) parameters work basically the same way they work in regular Node.js. See Using the TLS (SSL) Node.js module on Apigee Edge for details.
tty Disabled There is no standard input for scripts running on Apigee Edge.
url Supported  
util Supported  
vm Supported  
zlib Supported  

Understanding support for the http and https modules 

All Node.js applications running in Apigee Edge must use the http or https module to listen for incoming requests. If you were to deploy a script that doesn't listen for incoming requests, it would simply execute and exit.

The listen method of the http and https modules in Node.js takes a port number as a parameter. For example:

svr.listen(process.env.PORT || 9000, function() {
   console.log('The server is running.');
});

This "port" argument is required in Node.js, but Apigee Edge ignores this parameter. Instead, the API proxy in which the Node.js script runs specifies the "virtual host" that it listens on, and the Node.js application uses those same virtual hosts, just like any other Apigee Edge proxy.

Coding the port number to be retrieved from an environment variable conditionally, as shown in the example above, is considered a best practice by Apigee. 

Every environment in Apigee has at least one virtual host. The virtual host defines the HTTP settings for connection with the Apigee organization. All API proxies in an environment share the same virtual hosts. By default, two virtual hosts are available for each environment: default and secure. For more information, see Get a virtual host for an environment and API development lifecycle.

The apigeetool deploynodeapp command generates an Apigee Edge proxy wrapper around the Node.js application. When deployed, the Node.js application listens on the default virtual host defined for the environment. The URL for a Node.js application will always be http://{org_name}-{env_name}.apigee.net.

Handling incoming requests

Like other Apigee Edge applications, if the proxy application is set up to listen on the secure virtual host, then it will accept incoming requests using HTTPS.

Currently, more advanced setup, including custom CNAME support and custom TLS/SSL certificates, requires assistance from Apigee. For more on the secure virtual host, see API development lifecycle. See also Understanding support for the tls module

Handling outgoing requests

In addition to receiving incoming traffic, Node.js applications inside Apigee Edge may use the http and https modules to make outbound requests like any other Node.js application. These modules work just as they always do inside Node.js.

If you use custom TLS/SSL certificates or trust stores, the Apigee Edge support for outbound requests works differently. Contact Apigee Support if you have questions.

Understanding support for the tls module

Apigee Edge supports the Node.js tls module. This module uses OpenSSL to provide Transport Layer Security (TLS) and/or Secure Socket Layer (SSL) encrypted stream communication. You can use the tls module to create secure connections to backend services from Node.js applications running on Edge.

To understand how the tls module works on Apigee Edge, it's important to understand how virtual hosts are used on Apigee Edge. Every environment in Apigee has at least one virtual host. The virtual host defines the HTTP settings for connection with the Apigee organization. All API proxies in an environment share the same virtual hosts. By default, two virtual hosts are available for each environment: default and secure. For more information on virtual hosts, see Get a virtual host for an environment and API development lifecycle.

Now, let's look at how Apigee Edge handles TLS (SSL) communication for incoming and outgoing requests on Node.js applications:

Handling incoming requests

Depending on how virtual hosts are configured for your organization, Edge provides these options:

  • If the API proxy is configured to listen on the default virtual host, then it accepts requests over HTTP.
  • If the API proxy is configured to listen on the secure virtual host, then it accepts requests over HTTPS. The URL will be under the apigee.net domain, and a wildcard SSL certificate for *.apigee.net will be used. As long as apps make requests to the apigee.net domain, then the SSL certificate will validate normally.

To use custom TLS/SSL certificates for inbound traffic, see Apigee Support at the Support Portal.

Handling outgoing requests

You can make outgoing requests with the tls module the same way you would normally in Node.js. Basically, you need to add client-side keys and certificates (.pem files) to the resources/node directory and load them inside your script. For information on using the tls module and its methods, see the Node.js tls module documentation.

 

Why the cluster module is disabled

Apigee Edge does not support the "cluster" module, which allows Node.js applications to control when additional copies of an application are started and stopped, and to communicate with them. In the parlance of the "cluster" module, all Node.js applications are considered to be the "master."

However, Apigee Edge does deploy multiple instances of each application — two in most cases, although the system may be configured to run more if necessary.

That means that Node.js applications running inside Apigee Edge, like all Node.js applications, must assume that they will be processing many different requests "in parallel" using a single thread of control. However, the application must not assume that it is the only copy running in the world, though it also must not assume that there is some way to communicate with the other copies.

Advanced ScriptTarget Configuration

In the <TargetEndpoint> definition, the <ScriptTarget> element takes additional optional parameters besides <ResourceURL>. You can also pass command-line arguments and environment variables to a Node.js script using the <EnvironmentVariables> and <Arguments> parameters:
<TargetEndpoint name="default">
  <ScriptTarget>
     <ResourceURL>node://hello.js</ResourceURL>
     <EnvironmentVariables>
         <EnvironmentVariable name="NAME">VALUE</EnvironmentVariable> 
     </EnvironmentVariables>
     <Arguments>
         <Argument>ARG</Argument>
     </Arguments>
  </ScriptTarget>
</TargetEndpoint>

Get help

For help, see Apigee Customer Support.

Help or comments?

  • Something's not working: See Apigee Support
  • Something's wrong with the docs: Click Send Feedback in the lower right.
    (Incorrect? Unclear? Broken link? Typo?)