Zendro-dev / graphql-server

Skeleton NodeJS project for a graphQL server.
GNU General Public License v3.0
0 stars 1 forks source link

Make `models_index.js` invokable from any directory #29

Open asishallab opened 4 years ago

asishallab commented 4 years ago

When opening a interactive node shell not inside the root directory of graphql-server and requiring e.g.

var m = require('./graphql-server/models_index.js')

You get an error

Uncaught Error: ENOENT: no such file or directory, scandir './models'                                                                                                                                              
    at Object.readdirSync (fs.js:872:3)                                                                                                                                                                            
    at Object.<anonymous> (/home/cons/EMPHASIS-Layer/cenzontle_git_projects/Sandbox_real/SIAGRO/instance_3_gef/graphql-server/models_index.js:13:4)                                                                
    at Module._compile (internal/modules/cjs/loader.js:1156:30)                                                                                                                                                    
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
    at Module.load (internal/modules/cjs/loader.js:1000:32)
    at Function.Module._load (internal/modules/cjs/loader.js:899:14)
    at Module.require (internal/modules/cjs/loader.js:1042:19)
    at require (internal/modules/cjs/helpers.js:77:18) {
  errno: -2,
  syscall: 'scandir',
  code: 'ENOENT',
  path: './models'
}

Fix this by using path specifications that work always independently of from where models_index.js is required.

Look at __dirname and path.

tmvoe commented 4 years ago

The fix is now committed on the graphql-server. Branch: issue29-invokable-models-index Commit: https://github.com/ScienceDb/graphql-server/commit/e071fa1ff5c1d15aa938a2eead9cf88d270e54fc