Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
342 views
in Technique[技术] by (71.8m points)

node.js - Require modul not working when I migrate from parse to heroku

I migrated from parse to heroku and I am trying to get cloud code to work. Everything works fine when the cloud code file is blank, but when I add the require Stripe or Twilio lines in the main.js file, nothing in my app loads. What am I doing wrong?

package.json

"dependencies": {
"express": "~4.11.x",
"kerberos": "~0.0.x",
"parse": "~1.8.0",
"parse-server": "~2.2.12",
"stripe": "~4.9.0",
"twilio": "~2.9.2"
}

main.js

var Stripe = require('stripe');
Stripe.initialize('sk_test_xxxxxxx');
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

i had issues with this today

I did it by trial and error, here is what i remember

https://www.npmjs.com/package/stripe <- thats where i got the cloud code from

  1. in the root directory of your parse-server through command prompt i executed the following - npm install stripe
  2. then i added the stripe dependancy to package.json (this stack overflow post was the missing key) "stripe": "~4.9.0",
  3. the cloud code is as follows

Parse.Cloud.define("charge", function(request, response) {

var stripe = require('stripe')('sk_test_****');

stripe.customers.create({
  email: theEmailAddress
}).then(function(customer) {
  return stripe.charges.create({
    amount: yourAmount, 
    currency: yourCurrency,
    card: yourToken,
    description: yourDescription
  });
}).then(function(charge) {
  // New charge created on a new customer 
}).catch(function(err) {
  // Deal with an error 
});

});

  1. use that cloud code through your app and see if it works in your stripe dashboard (you must check in the dashboard)

so the two 'breakthroughs' came when i added stripe as a dependancy in package.json and also can you see that var stripe = require is inside the the cloud code function


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...