Closed derhyl closed 7 years ago
Hi @lulucious,
Yes, If you have installed v1.0.0 then the usage is:
var Nexmo = require('nexmo');
var nexmo = new Nexmo(...);
These quick start examples should help: https://github.com/nexmo-community/nexmo-node-quickstart
If they don't, could you please provide some example code? Or a repo that demonstrates the problem would be great too.
Thanks.
well this is EXACTLY what I did... Do you confirm that : applicationId, privateKey and options are not mandatory? Are you sure npm install nexmo is pointing to the right release?
By the way there is an extra } in your readme file : var nexmo = new Nexmo({ apiKey: API_KEY, apiSecret: API_SECRET, applicationId: APP_ID, privateKey: PRIVATE_KEY_PATH, }, options });
Do you confirm that : applicationId, privateKey and options are not mandatory?
Yes, I can confirm that applicationId
and privateKey
are not mandatory.
Are you sure npm install nexmo is pointing to the right release?
https://www.npmjs.com/package/nexmo
Is correctly pointing to 1.0.0.
If you run:
git clone git@github.com:nexmo-community/nexmo-node-quickstart.git
cd nexmo-node-quickstart
mv .env-example .env
And populate the values in the .env
with the EXAMPLE_FROM_NUMBER
being a virtual number you are renting from Nexmo and EXAMPLE_TO_NUMBER
your number. Then run:
node sms/send.js
You phone should receive an SMS. I've just tested this.
If you look at sms/send.js
you'll see it uses the constructor without the applicationId
and privateKey
:
var Nexmo = require('nexmo');
var nexmo = new Nexmo({apiKey: API_KEY, apiSecret: API_SECRET}, {debug:true});
nexmo.message.sendSms(FROM_NUMBER, TO_NUMBER, 'Hello from Nexmo!');
I hope this helps.
Ok I found the problem, but I can't explain it easily...
the presence of this line in the file that requires nexmo breaks my call to the module :
body.match(/â|ê|î|ô|û|ë|ï|ç|ù/g)? then 'unicode' else 'text'
Any idea?
@lulucious can you provide any more context? Could you provide a code sample that reproduces the problem?
If a special caracter, or a single quote (’) is in your js file (even in a commented line!!), Node cannot compile the nexmo module...
@lulucious I'm not sure this is the issue. See https://github.com/cbetta/node-nexmo-unicode-example for proof that this works fine.
Did you actually put nexmo in your package.json
?
yes of course! I really did a lot of investigation before finding the guilty lines... This only worked when I removed that line and the one with the slanted quote. Even commenting the line did not help. Only removing it did. I can't explain and i agree that it sounds unrelated but it is the case...
Just add on line 2 :
nexmo = new Nexmo({ apiKey: "yyy", apiSecret: "xxx" }, { debug: true });
@lulucious still works for me https://github.com/cbetta/node-nexmo-unicode-example (updated with your code)
@lulucious you have a typo on line 1, it needs to be var Nexmo
with a capital N
Hmm.. it is working when i run it in js but not with coffeescript
This is ok :
Nexmo = require('nexmo');
nexmo = new Nexmo({
apiKey: "ii",
apiSecret: "hh"
}, {
debug: true
});
body = "";
body = body.replace(/’/g, "'");
console.log("ok");
But this is not :
Nexmo = require('nexmo')
nexmo = new Nexmo({apiKey:"ii", apiSecret:"hh"}, {debug:true})
body = ""
body = body.replace(/’/g,"'")
console.log "ok"
However, it only triggers a problem with nexmo module! weird...
@lulucious both of them work fine here in js
and coffee
. I'm 99% certain your error is just referring to the first line in the code due to a syntax error (incorrectly). I'm pretty sure it's not our library in this case. I'd like to close this issue until we can actually prove this to be an issue with our library because I can't see how it is.
You ok with that?
@lulucious FYI I ran this code below and it works fine here.
Nexmo = require('nexmo')
nexmo = new Nexmo({apiKey:"ii", apiSecret:"hh"}, {debug:true})
body = ""
body = body.replace(/’/g,"'")
console.log "ok"
@lulucious just to be sure: what NPM/Node versions are you running?
v4.4.3
that same code returns :
Nexmo = require('nexmo')
nexmo = new Nexmo({apiKey:"ii", apiSecret:"hh"}, {debug:true})
body = ""
body = body.replace(/’/g,"'")
console.log "ok"
ReferenceError: Nexmo is not defined
at new Nexmo (/home/ldmint/Public/node-nexmo-unicode-example-master/node_modules/nexmo/lib/Nexmo.js:77:25)
at Object.<anonymous> (/home/ldmint/Public/node-nexmo-unicode-example-master/app.coffee:2:13)
at Object.<anonymous> (/home/ldmint/Public/node-nexmo-unicode-example-master/app.coffee:1:1)
at Module._compile (module.js:460:26)
at Object.exports.run (/home/ldmint/.nvm/versions/node/v0.12.7/lib/node_modules/coffee-script/lib/coffee-script/coffee-script.js:134:23)
at compileScript (/home/ldmint/.nvm/versions/node/v0.12.7/lib/node_modules/coffee-script/lib/coffee-script/command.js:224:29)
at compilePath (/home/ldmint/.nvm/versions/node/v0.12.7/lib/node_modules/coffee-script/lib/coffee-script/command.js:174:14)
at Object.exports.run (/home/ldmint/.nvm/versions/node/v0.12.7/lib/node_modules/coffee-script/lib/coffee-script/command.js:98:20)
at Object.<anonymous> (/home/ldmint/.nvm/versions/node/v0.12.7/lib/node_modules/coffee-script/bin/coffee:7:41)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)
at node.js:814:3
@lulucious can you make me a project with package.json and everything like I did with https://github.com/cbetta/node-nexmo-unicode-example that shows it not working?
@lulucious tested in Node 4.4.3 and it all works fine here. Both coffeescript and Node.
FYI I am running CoffeeScript version 1.11.1
try running coffee app.coffee https://github.com/lulucious/nexmo-weird-pb
@lulucious I'll get back to this later tonight.
@lulucious I tried your code and it all still works pretty fine for me. Both the Node and the Coffee version. There's something on your system definitely wrong.
@lulucious could you try a different Node version on your machine for me? Just want to see if that makes it go away.
Closing due to inactvity
Hi, It is impossible to instantiate Nexmo. I always an error : ReferenceError: Nexmo is not defined, trigerred on /node_modules/nexmo/lib/Nexmo.js:76:15. Of course, I did npm install nexmo before... Can you please help on that? Thanks a lot,