Polymorphic Node

To write your Jets Lambda functions in node, it would look like this:

app/controllers/posts_controller.rb:

class PostsController < ApplicationController
  node :node_example
end

You add your corresponding node code in the posts_controller/node folder:

app/controllers/posts_controller/node/node_example.js:

'use strict';

exports.handler = function(event, context, callback) {
    var message = 'hi from node ' + process.version;
    var body = {'message': message};
    var response = {
      statusCode: "200",
      headers: {
          'Content-Type': 'application/json',
      },
      body: JSON.stringify(body)
    };
    callback(null, response);
};

Notice, how with the node code, you must handle returning the proper lambda proxy structure to API Gateway.

Lambda console

Default Handler Name

The default node handler name is handler. The default can be changed with the handler method. Example:

app/controllers/posts_controller.rb:

class PostsController < ApplicationController
  handler :handle
  node :node_example
end

The node code would then look something like this:

exports.handle = function(event, context, callback) {
  ...
};

You can also set the handler for the entire class. Example:

class PostsController < ApplicationController
  class_handler :handle
  # ...
end

Pro tip: Use the <- and -> arrow keys to move back and forward.

Edit this page

See a typo or an error? You can improve this page. This website is available on GitHub and contributions are encouraged and welcomed. We love pull requests from you!