Skip to main content

Monorepo

If your app lives inside a monorepo (for example managed by lerna), you should consider creating core package to handle configuration and model definition. All packages using models should then depend on the core package.

This is an example of lerna package structure

spotify-stats-loader/
โ”œโ”€ node_modules/
โ”œโ”€ packages/
โ”‚ โ”œโ”€ core/
โ”‚ โ”‚ โ”œโ”€ models.js
โ”‚ โ”‚ โ”œโ”€ settings.js
โ”‚ โ”‚ โ””โ”€ package.json
โ”‚ โ”œโ”€ episode-loader/
โ”‚ โ”‚ โ”œโ”€ index.js
โ”‚ โ”‚ โ””โ”€ package.json
โ”‚ โ””โ”€ stats-loader/
โ”‚ โ”œโ”€ index.js
โ”‚ โ””โ”€ package.json
โ”œโ”€ .gitignore
โ”œโ”€ package.json
โ”œโ”€ package-lock.json
โ””โ”€ README.md

Dependencies#

Make sure that both episode-loader and stats-loader depend on the core. This would be packages/episode-loader/package.json

{
"name": "stats-loader",
"dpendencies": {
"core": "file:../core"
}
}

Requiring models#

This could be body of the packages/episode-loader/index.js

const { SpotifyEpisode } = require('core/models')
const runJob = async () => {
const models = await SpotifyEpisode.objects.all()
console.log(models)
}
module.exports = {
runJob
}