2

I installed with success a Parse-Server on my local machine from this GUID. I tried first with global installation, then I tried to understand better (It's the first time I see something related to Node.js) and I installed in a local directory. I think it should be the same.

this is what I done:

npm install parse-server parse-dashboard underscore

this is how the directory looks like:

/parse: ls
dashboard-config.json       
logs              
node_modules

ls node_modules/underscore
LICENSE        
README.md      
package.json   
underscore-min.js
underscore-min.map 
underscore.js

ls node_modules/parse
parse/           
parse-dashboard/ 
parse-json/      
parse-server/
parseurl/

Next I try to include also the cloud code I developed. the main.js has this content:

//var Image = require("parse-image");
var _ = require('underscore');
...

This is how I started the server:

node_modules/parse-server/bin/parse-server \
  --appId APPID --masterKey MASTERKEY \
  --databaseURI mongodb://localhost:27017/MyAPP \
  --cloud /absolutepathfor/MyApp/cloud/main.js 

and the error I got

module.js:341
throw err;
^

Error: Cannot find module 'underscore'
at Function.Module._resolveFilename (module.js:339:15)
at Function.Module._load (module.js:290:25)
at Module.require (module.js:367:17)
at require (internal/module.js:16:19)
at Object.<anonymous> (/Users/......./main.js:2:9)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Module.require (module.js:367:17)

How can I include in this case underscore, but in any case other libraries?

[update]

I installed globally the underscore lib (node install -g underscore).

I create a symbolic link cloud -> < path where is located cloud/main.js >

Next I created package.json with npm init command

I launch again npm install

I created app.js like described in the guid and I configured it using the same parameters above.

I started the server with node app.js

all gone fine. the problem right now is in permissions on create a new document, where I should already have that grants, but this will be another problem to solve. I hope this can help somebody else

tylyo
  • 572
  • 5
  • 16

2 Answers2

1

I hit the same problem and error message. I did the followings and it works

  1. npm install underscore
  2. use this path: var _ = require('../node_modules/underscore/underscore.js')

Refer to more details in this post.

Can't get 'underscore' to work with parse server

Community
  • 1
  • 1
user3204765
  • 124
  • 5
1

I just sorted a similar issue while transferring Parse.com CloudCode to a self hosted Parse Server on Nodejs; in one of the controller we had the line

var _ = require('underscore.js'); It had to be done like this on Parse.com. But now as we are on NodeJS and have NPM—it's enough to just do:

var _ = require('underscore'); (ie: drop the .js extension)

jrgd
  • 519
  • 3
  • 25