0

enter image description here

I'm getting started with nodejs and the serverless framwork. in some of the examples i've seen and even used the following code (from https://www.serverless.com/framework/docs/providers/aws/guide/functions/):

// handler.js
module.exports.functionOne = function(event, context, callback) {};

2 questions:

1) does module.exports have anything to do with the common node method of making functions available to other nodules?

2)What is the context they are referring to here? based on http://ryanmorr.com/understanding-scope-and-context-in-javascript/

I see:

Every function invocation has both a scope and a context associated with it. Fundamentally, scope is function-based while context is object-based. In other words, scope pertains to the variable access of a function when it is invoked and is unique to each invocation. Context is always the value of the this keyword which is a reference to the object that “owns” the currently executing code.

Does this apply here?

user1592380
  • 34,265
  • 92
  • 284
  • 515
  • About `module.exports` this could help [https://stackoverflow.com/questions/5311334/what-is-the-purpose-of-node-js-module-exports-and-how-do-you-use-it](https://stackoverflow.com/questions/5311334/what-is-the-purpose-of-node-js-module-exports-and-how-do-you-use-it) – Daniele Ricci Jun 06 '20 at 01:15

1 Answers1

1

The export is standard node.js, this is what maps your function implementation to the function declaration inside your serverless.yml

The context object is the AWS Lambda context (https://docs.aws.amazon.com/lambda/latest/dg/nodejs-context.html). If you look closely the example you linked is for AWS, the signature for the handler will be different for other cloud platforms.

Ville Rinne
  • 801
  • 1
  • 7
  • 15