1.0.4 • Published 5 years ago

dependency-for-microservice v1.0.4

Weekly downloads
5
License
ISC
Repository
-
Last release
5 years ago

Description

Notice that we have duplicated our models from the other services - this is bad, we have to extract the common code in to a npm module that we can then import in to our project just like any other package.

The thing is that microservice search does not require its own database, it does not require its own model in like a very basic example - it does not need it. But what we do need - is to know how to basically get data from the database, we need to be able to need what the other services that we want to be able to search for. We need to have some type of connection.
The idea is - have common code. If everythimg running on Node.js and we have things that need to be shared between different modules or different microservices. So that I put it in a npm package.
That makes it very easy for us to move common code amongst our projects, we do not have to copy and paste duplicate.
Because this is very dangerous - for example, I changed the book's module in my book's microservice, then I have to make sure that I'm changing it here /search/src/app.js as well. That's not so nice.

Source Code

'use strict'

const mongoose = require('mongoose')
const Schema = mongoose.Schema

const bookSchema = new Schema({
  name: String,
  type: { type: String, default: 'book' },
  createdAt: { type: Date, default: Date.now }
})

const videoSchema = new Schema({
  name: String,
  type: { type: String, default: 'video' },
  createdAt: { type: Date, default: Date.now }
});

module.exports = {
  Video: mongoose.model('Video', videoSchema),
  Book: mongoose.model('Book', bookSchema)
}
1.0.4

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.3

5 years ago

1.0.0

5 years ago