0

Here is my code: http://pastebin.com/rZKRTGUB

I am not sure why I am getting require is not defined on Line 4

Blood_Wolf89
  • 65
  • 2
  • 9

2 Answers2

2

require is part of the node runtime environment and does not exist in browsers. It looks like you're trying to run this in the browser (in the <script> tags). Likely, you should be creating a server in node and then using the code you've written to talk to the database.

Matthew Brooks
  • 521
  • 2
  • 5
  • Im new to node. How would I make a server that would talk to this code? EDIT: If I use a node server will the script run all the time without it being opened in a browser? – Blood_Wolf89 Mar 13 '16 at 05:46
  • This is a very big question, but in short, this code would be *part* of a server. You should look for tutorials on creating servers in node. Express is the most popular framework to let you do this quickly and easily, but you should be sure to learn the fundamentals of how servers and browsers work together. – Matthew Brooks Mar 13 '16 at 06:04
  • Is there a way to get a good example of the server file and how to link my bot to it? I have the express files already. What do I do? I am new to node and never used express before. – Blood_Wolf89 Mar 13 '16 at 07:57
  • I'm sorry, but it's too much to explain here. You need to read tutorials and do research on your own. There are plenty of great resources you can find through google searches. If you don't work to have a solid understanding of what you're doing, you will be stuck at every new problem without the skills to get yourself unstuck. If you spend time, build a simple http server to send static content, then move on from there, you'll have a much better idea of what you're doing. – Matthew Brooks Mar 13 '16 at 21:25
0

Yours is client side code, so require() is obviously not defined.

You either move your code in a node server or you drop http://requirejs.org/docs/download.html in your script if you want to use that API in the browser.

Francesco Pezzella
  • 1,755
  • 2
  • 15
  • 18