Serving the API from a submodule

When we run our tests, we want to make sure that our backend API is running using the NODE_ENV environment variable set to test. At the moment, we are doing this manually. However, it's more ideal to add it as part of our test script. Just as we did for our Swagger UI, we can use Git submodules to include the Hobnob API repository in the client's repository without duplicating the code:

git submodule add git@github.com:d4nyll/hobnob.git api

Now, to make life easier for later, add the following NPM scripts to package.json:

"api:init": "git submodule update --init","api:install": "yarn install --cwd api","api:serve": "yarn --cwd api run build && dotenv -e api/.env.example node api/dist/index.js","api:update": ...

Get Building Enterprise JavaScript Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.