In index.js you are not exporting the connection object, you are only exporting 
router object. That is why you are getting the error when you reference 
connection object in booksModel.js. You could try the following:
Step 1: In index.js include connection in the module exports as below:
module.exports={
  router,
  connection
}
Step 2: To reference it in booksModel.js, do below:
const connection = require('../routes/index').connection;

Step 3: Use connection to query your db.

Let me know how it goes.

-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/2fece48a-7f49-4980-b9dd-4f683b85a7c1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to