8

I am a complete Node.js newbie and struggling with the basics. Running this code on the server:

var http        = require("http"),
    sys         = require("util"),
    io          = require("socket.io"),
    GlobTrie    = require("glob-trie.js");

Gives me an exception at the first require:

Uncaught ReferenceError: require is not defined
(anonymous function)

Any thoughts?

Best regards, Ben.

Ben
  • 6,026
  • 11
  • 51
  • 72
  • 5
    How are you running the code? – thejh Dec 06 '11 at 18:07
  • Hi @thejh Apologies for not being clear. I have a test.html file within the Node dir. I run this locally using a browser. This loads my server.js file (with the above code) using the following: ` ` Appreciate any comments. Regards, Ben. – Ben Dec 07 '11 at 10:03
  • close vote because the author considers it to be – thejh Dec 16 '11 at 16:17

2 Answers2

2

Node.js is run on the server side, not on the browser side.

Check out more about Node here: What is Node.js?

Community
  • 1
  • 1
alessioalex
  • 62,577
  • 16
  • 155
  • 122
  • Hi @alessioalex I am running my server code (server.js) on the server. This is running using Node. Node starts fine. I then load my test.html (see above comment) and thats what logs the exception, referencing the server.js. – Ben Dec 07 '11 at 10:53
  • Why are you trying to include server.js on the frontend..? – alessioalex Dec 07 '11 at 10:54
  • Hi @alessioalex The front end script utilises the server side script also. The example I am trying is here https://github.com/rbranson/brokaw Regards, Ben – Ben Dec 07 '11 at 13:28
  • I think that's kind of old and non-functional? Look at the notes at the bottom: Tested on node v0.2.4. Experimental etc – alessioalex Dec 07 '11 at 13:35
  • Yes, I did spot that, perhaps not the best intro to Node for me ;) Given in was only a few lines of code, I was hoping to get going. Thanks for your assistance. Ben. – Ben Dec 07 '11 at 15:43
  • Here are some resources for learning Node: http://delicious.com/alessioaw/nodejs http://stackoverflow.com/tags/node.js/info https://github.com/joyent/node/wiki/Resources – alessioalex Dec 07 '11 at 15:45
1

Case closed, I was including the wrong file on the client!

Sorry to waste people time, but thanks for the Node links.

Bijoy Thangaraj
  • 5,434
  • 4
  • 43
  • 70
Ben
  • 6,026
  • 11
  • 51
  • 72