title: Mocking Repository but Then Swapping Out for Real Implementation in Node.js
body: <p>I'm building a Repository layer with higher level API for my abstractions above to make calls to the database persistence.  But since JavaScript doesn't have the concept of Interfaces like a language such as C# or Java does, how do you swap out the mock for the real implementation?</p>
  
  <p>I prefer creating custom mocks, node repository modules with data persitence high level methods in them vs. Sinon.js or something like that.</p>
  
  <p>If I'm creating node modules, then how?  I could send in a mock representation of the repository where I mock out what the repository methods are doing but then the actual node modules using those repository modules would need to use the real repository implementation that calls the real database.  How is this done in Node?  I want to just inject via a property, I don't want some gigantic injection IoC framework either.</p>
  
  <p>Since there's no concept of an interface then wtf do you do in Node/JS?  I have to create a data layer below the repository (whether it be a custom set of modules making real query calls to Postgres or whether I'm using Mongoose or whatever it may be, I need a DL set of modules that the repository calls for tis real DB calls under the hood).</p>
  
  <p>And lets say I do choose to use some framework like Sinon.js, what's the common interface for the module you're mocking that can be shared by the mocking framework and the real module?</p>