Function handler from folder outside project

Hi,
is it possible to point function handler to file outside project folder?

ex :
my folder structure is

A ==> this is the project folder

  • handler.js
  • serverless.yml

B

  • node_modules
  • handler_b.js ==> this have some library from npm

can i do something like this ?
functions:
getAll:
handler: B/handler_b.getAll

because i get error
Debug: internal, implementation, error

do i need to npm install all library needed in folder B into my folder A ?

Nesting your handler is perfectly acceptable, e.g. handler: B/handler_b.getAll should work just fine for routing your requests. I’m not sure I understand why you’d have a separate node_modules folder in a subdirectory of a project, but Node.js will typically look for a node_modules folder recursively from the directory of the file.

My suggestion would be to package your entire Serverless app as ONE single node module with a single package.json. If the two handlers are coupled anyway, I’m not sure what the benefit is of separating them within the same function.

If there is more context to this, please share.

1 Like