Sunday, 29 September 2019

How to include nodejs modules in sub directory

I have a directory structure like this for an AWS Lambda layer.

main > nodejs > node_modules

I have a test.js file to test functionality before uploading to AWS. Is it possible to have my test.js file in the Main folder instead of the nodejs folder and still have it pick up the modules in the nodejs folder?

I'm asking because you compress the nodejs folder to upload for the AWS Lambda Layer but I don't want to include my test.js file in the archive.

UPDATE: An answer below helped my find the solution. You just enter the full path to the module in require.

require('./nodejs/node_modules/my_module');


from How to include nodejs modules in sub directory

No comments:

Post a Comment