0

I am very new to AWS Lambda and Node.js, so apologies for the elementary question. I have two JS files in my Lambda project's root directory:

index.js

engageMessage(); //For testing purposes - throws error

exports.handler = async (event) => {
    // TODO implement
    const response = {
        statusCode: 200,
        body: JSON.stringify('This is index'),
    };
    return response;
};

messenger.js

function engageMessage() {
    console.log("Messenger, checking in!");
};

How do I call engageMessage() from my index.js file? Each time I try, I get a "TypeError: engageMessage is not a function" message, and am unsure of how to properly reference/import/require messenger.js.

1 Answer 1

1

In messenger.js you need to export your function

module.exports = { engageMessage }

Then require it in your index.js

const { engageMessage } = require("./messenger.js")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.