I am trying to run this piece of code from http://coffeescriptcookbook.com by embedding it in html.
net = require 'net' domain = 'localhost' port = 9001 connecting = (socket) -> console.log "Connecting to real-time server" connection = net.createConnection port, domain connection.on 'connect', () -> console.log "Opened connection to #{domain}:#{port}" connecting connection connection.on 'data', (data) -> console.log "Received: #{data}" connection.on 'end', (data) -> console.log "Connection closed"
This code is in a file called client.coffe, and when I run it with the coffee: coffee client.coffe command it works fine and connects to the server, but when I insert it into the html file and open it, I get this error: Missed ReferenceError: require is undefined.
My html script tags look like this:
<script src="http://jashkenas.github.com/coffee-script/extras/coffee-script.js" type="text/javascript" charset="utf-8" ></script> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js" type="text/javascript" charset="utf-8"></script> <script src="{% get_static_prefix %}functions.js" type="text/javascript" charset="utf-8"></script> <script src="{% get_static_prefix %}jquery.dajax.core.js" type="text/javascript" charset="utf-8"></script> <script src="{% get_static_prefix %}client.coffee" type="text/coffeescript" charset="utf-8"></script>
Any ideas?
source share