Thursday, 15 May 2014

node.js - Express.js db module after refactoring routes -


I had a simple app in node / express and after seeing a course on the net, it helped me to help me Does the app but after getting this done I got a little problem

The problem is that my routes are using a variable named "db" which is an example of an access point.

DB = {User: New NEDB ({filename: "db / users.db", autoload: true}}}

Of course I To declare it, I can copy the code of 5 lines at the top of every path file, but it will not be very dry.

I tried to export it to a different file

and then import it into each file on it:

 

Code> var db = require (". / Db"); ...

however It did not work as expected (error was: module can not be found './db')

This is my simplified structure

  DB / User DB Path / users. Js app.js db.js  

Any ideas or best practice / elegant way to solve this?

You have a relative path .

If you need the inside / root folder, then You must type

  var db = require ("../db");  

No comments:

Post a Comment