# How To Structure Multi-Service Codebase With Shared Library Code

**URL:** <https://forum.serverless.com/t/how-to-structure-multi-service-codebase-with-shared-library-code/1385>\
**Category:** Serverless Framework\
**Created:** [February 24, 2017, 3:30pm UTC](https://forum.serverless.com/t/how-to-structure-multi-service-codebase-with-shared-library-code/1385 "2017-02-24T15:30:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jthomerson](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/jthomerson/32/481_2.png) [@jthomerson](https://forum.serverless.com/u/jthomerson)\
**Post date:** [February 24, 2017, 3:30pm UTC](https://forum.serverless.com/t/how-to-structure-multi-service-codebase-with-shared-library-code/1385/1 "2017-02-24T15:30:40Z")

</div>

Does anyone have any suggestions on how to structure a codebase that contains multiple services and has some library code that can be shared between various services? For example:

```auto
my-project
  - services
    - foo-service
      - serverless.yml
      - src/FooService.js
    - bar-service
      - serverless.yml
      - src/FooService.js
  - lib/src/SomeSharedLibrary.js

```

If you then have this in your serverless.yml file:

```auto
package:
  include:
    '../lib/src/**'

```

Your zip that serverless builds will result in this:

```auto
src/FooService.js
lib/src/SomeSharedLibrary.js

```

So in FooService.js you must reference SomeSharedLibrary with `../lib/src/SomeSharedLibrary` even though the real path is `../../lib/src/SomeSharedLibrary` (notice the extra level of nesting).

That works, **except then tests won’t work** because when you run tests FooService can’t find SomeSharedLibrary.

So, it seems that either:

1. I need to have a different way of structuring the codebase with the shared code, or
2. I need to do some magic for testing to make it mimic the directory structure that Serverless will create for my deployed code, or
3. I need to use symlinks or something to make the lib code appear _inside_ the service that uses it.

- That’s what was done here: [Folder structure for multiple servies with shared library?](http://forum.serverless.com/t/folder-structure-for-multiple-servies-with-shared-library/1153/8)

---

<div class="post-metadata">

**Author:** ![tommedema](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/tommedema/32/1257_2.png) [@tommedema](https://forum.serverless.com/u/tommedema)\
**Post date:** [November 12, 2017, 10:25am UTC](https://forum.serverless.com/t/how-to-structure-multi-service-codebase-with-shared-library-code/1385/2 "2017-11-12T10:25:30Z")

</div>

It sounds like you simply need to use a package manager, and then import (es6) or require the package after installing it with npm or yarn.

If your shared code can be made public, publish it as libraries to NPM.

If not, consider having a private NPM registry. Alternatively, you can include packages with direct references to private github repositories.
