Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6851691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:16:44+00:00 2026-05-27T01:16:44+00:00

I am trying to run this piece of code taken from http://coffeescriptcookbook.com embedding it

  • 0

I am trying to run this piece of code taken from http://coffeescriptcookbook.com embedding it into an 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 file named client.coffe and when i run it with the coffee command: coffee client.coffe it runs fine and connects to the server, but when I embbed it in a html file and open it i get this error: Uncaught ReferenceError: require is not defined.

My html script tags looks 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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T01:16:45+00:00Added an answer on May 27, 2026 at 1:16 am

    This won’t work in the browser.

    First issue: Stuff in the browser isn’t allowed to connect to other servers or ports than it’s coming from for security reasons. Also, you don’t get real sockets, just HTTP.

    Second issue: require is a node.js command you’ll only be able to use in node.js (that is, when you run a javascript file with the node command or a coffeescript file with the coffee command). The net module belongs to node.js and will never work this way in the browser.

    If you want to talk to the server in realtime from inside the browser, I recommend the socket.io module which uses websockets, flashsockets and HTTP (those are usable from within the browser).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to run this piece of code: strSQL = SELECT * FROM ORDER_DATA
I am trying to run this code: ItemTaxonomy iTaxonomy = from itemTaxonomy in connection.ItemTaxonomy
I am trying to run this SQL from ASP.NET 2005 but am getting an
I've run into this problems several times before when trying to do some html
Trying to run this piece of code: void print_matrix(matrix* arg) { int i, j;
I'm trying to run this piece of code inside my onCreate method as an
I'm trying to run this code: let coins = [50, 25, 10, 5, 2,1]
I am trying to understand how this piece of self-replicating code works (found here
I have this little piece of code, and I'm trying to convert a JSON
I have been trying to follow this example (download the source code from a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.