Unable to get underscore for parsing server

I just migrated the Parse Server and everything works except the cloud code. I came to understand that this is because in my main.js I need the Underline library.

This is my cloud code feature:

Parse.Cloud.define("ReadyUp", function(request, response) { var _ = require('underscore'); var fbid = request.user.get("fbid"); var query = new Parse.Query("Spel"); query.equalTo("lobby", fbid); query.find().then(function(results) { _.each(results, function(spel) { spel.addUnique("ready", fbid); }); return Parse.Object.saveAll(results); }).then(function(result) { response.success(result); }, function(error) { response.error(error); }); }); 

This code worked without errors before porting. I assume the requirement does not find the desired folder. To create a folder structure, it looks like this:

Cloudcode Location: mainfolder-> cloud-> main.js

Subtree library: Main folder -> node_modules -> underline (folder)

Is the code broken or the folder structure damaged?

Thanks in advance!

/ Martin

+5
source share
2 answers

You must specify the correct underline file. I have done the following:

 var _ = require('../node_modules/underscore/underscore.js') 
+4
source

Add underline to your dependencies in package.json , either manually, or run npm install underscore --save

This will result in the following line:

 "underscore": "^1.8.3" 

From now on you can really do it

 var _ = require('underscore'); 
+1
source

Source: https://habr.com/ru/post/1242957/


All Articles