0

I have installed Node from:

Node

and run this in cmd:

npm install twilio

I then tried the example code provided by Twilio:

var accountSid = 'MyAccountSidHere';
var authToken = "MyAccountAuthTokenHere";
var client = require('twilio')(accountSid, authToken);

client.sms.messages.create({
    body: "Jenny please?! I love you <3",
    to: "SomeNumber",
    from: "MyNumber"
}, function(err, message) {
    process.stdout.write(message.sid);
});

Saved this to MyFile.js file and double clicked it.

I get the error message:

ReferenceError: require is not defined

This is my first encounter with JavaScript and I found a lot of similar questions, but have not been able to solve this.

I am to use this with QML, so I want to load it using:

import "MyFile.js" as MyFile

then call the javascript code as a function.

Kevin Burke
  • 61,194
  • 76
  • 188
  • 305
uniquenamehere
  • 1,869
  • 3
  • 31
  • 60
  • What do you mean when you say "Saved this to MyFile.js file and double clicked it." Do you actually run the code in node.js using the commandline 'node' command? Require is a function of node.js that is global in any node.js module, so go to the getting started docs on http://nodejs.org/ and learn how to run a node.js module. – douwe Nov 15 '13 at 09:32

1 Answers1

3

I've read a little into QML and I don't see how you could use a node.js module in QML. QML is used as a language where QT is the JavaScript engine and node.js is a server-side Javascript engine.

The require() function is a core function of node.js which is part of the engine. It's not something language-specific just like the window object in browser-based Javascript is not something in the Javascript language.

As I said in my comment, you should check out what node.js actually is: a server-side JavaScript engine, which executes JavaScript files. It is not a framework which you could load into another engine like QT.

Your code will run if you use it like this from the command-line:

node MyFile.js

I doubt this is helpful for your use-case as a QML import though.

douwe
  • 1,305
  • 10
  • 12