node.jsdebuggingconfigurationdojojsonreststore

Starting Persevere from another folder than it was installed in


I installed Perservere with "npm install persevere-example-wiki", as specified here http://persvr.org/Installation. Starting the server from the folder node_modules/persevere-example-wiki DOES work as specified. Here is the server log for my request

$ pwd
PROJECT_ROOT/node_modules/persevere-example-wiki
$ node index.js 
Listening on port 8282
persevere>createContext { id: 'Example',
  content: 'this is a test\n\n   and some other test',
  createdBy: 'admin',
  status: 'published',
  lastModifiedBy: 'qwe123' }
createContext public not found
error writing [object Object]TypeError: first argument must be a string or Buffer

However there are a few things I do not understand: Even though I provided the right database credentials, nothing gets saved in the database server, every data I have entered into the application is saved only in the "node_modules/persevere-example-wiki/data" folder, in plain text JSON files.

How can I start persevere from a different folder than node_modules/persevere-example-wiki? I am convinced there is a way to configure paths, I would like to know how. I tried copying the local.json to the grandparent folder and tried to start from there, but a lot more errors appear:

$ node node_modules/persevere-example-wiki/index.js 

fs.js:427
  return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
                 ^
Error: ENOENT, no such file or directory 'data/User'
    at Object.fs.openSync (fs.js:427:18)
    at Object.exports.openSync (/home/bogdanbiv/WebstormProjects/life-tracker3/node_modules/persevere-example-wiki/node_modules/promised-io/fs.js:154:27)
    at initializeFile (/home/bogdanbiv/WebstormProjects/life-tracker3/node_modules/persevere-example-wiki/node_modules/perstore/store/memory.js:213:21)
    at store.setPath (/home/bogdanbiv/WebstormProjects/life-tracker3/node_modules/persevere-example-wiki/node_modules/perstore/store/memory.js:257:3)
    at Object.store.setPath (/home/bogdanbiv/WebstormProjects/life-tracker3/node_modules/persevere-example-wiki/node_modules/perstore/store/notifying.js:20:4)
    at Object.notifyingStore.setPath (/home/bogdanbiv/WebstormProjects/life-tracker3/node_modules/persevere-example-wiki/node_modules/perstore/store/replicated.js:16:20)
    at Object.facet.(anonymous function) [as setPath] (/home/bogdanbiv/WebstormProjects/life-tracker3/node_modules/persevere-example-wiki/node_modules/perstore/facet.js:719:37)
    at Object.security.getUserModel (/home/bogdanbiv/WebstormProjects/life-tracker3/node_modules/persevere-example-wiki/node_modules/pintura/security.js:88:15)
    at Function.Authentication (/home/bogdanbiv/WebstormProjects/life-tracker3/node_modules/persevere-example-wiki/node_modules/pintura/jsgi/auth.js:14:11)
    at JsgiApp (/home/bogdanbiv/WebstormProjects/life-tracker3/node_modules/persevere-example-wiki/node_modules/pintura/pintura.js:58:37)

Right now, the Persevere framework itself seems overly complex - or perhaps it's just the documentation problem. Anyway it does not seem a good idea to have a single very complex example. Generally, I prefer building up from smaller examples.


Solution

  • Use the NODE_PATH environment variable to add PROJECT_ROOT/node_modules/persevere-example-wiki as a default directory to search:

       export NODE_PATH=$PROJECT_ROOT/node_modules/persevere-example-wiki
    

    References