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 6621199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:13:53+00:00 2026-05-25T21:13:53+00:00

I’m teaching myself Coffeescript/node and, of course, the only way to do this is

  • 0

I’m teaching myself Coffeescript/node and, of course, the only way to do this is with TDD. That means I’m also teaching myself vows. There are, I think, at least two problems. One is — where does the asynchronous code to get the HTTP response lie? And the other is — why won’t the server send me a response back? The console displays “Request sent” but it does not display “Request received.”

Here is the test file:

vows = require 'vows'
assert = require 'assert'
EventEmitter = require('events').EventEmitter

Server = require('./web').WebServer
Client = require('../lib/client').Client
Request = require('../lib/request').Request

PORT = 8080
SERVER = new Server PORT
SERVER.start()
CLIENT = new Client PORT, 'localhost'
REQUEST = new Request 'GET', '/'

vows
  .describe('Sending a request to the server')
  .addBatch
    'The request is sent': 
      topic: -> 
        CLIENT.transmit(REQUEST, @callback)
        return

      'The response should be what the server sent back': (err, request) ->
        body = ""
        request.on 'response', (response) ->
          response.on 'data', (chunk) -> body += chunk
        assert.equal body, /Ooga/

  .export(module)

Here is the WebServer object:

Http = require('http')

exports.WebServer = class WebServer

  processRequest = (request, response) ->
    console.log 'Request received!'
    console.log request
    response.writeHead 200, {'Content-Type':'text/plain'} #, 'Content-Length':'6'}
    response.write 'Ha-ha!'
    response.end

  constructor: (@port) ->
    @server = Http.createServer processRequest

  start: ->
    @server.listen @port

  stop: ->
    @server.close()

Next up is the client code – also very simple.

Http = require 'http'
Request = require('./request').Request

exports.Client = class Client

  constructor: (@port, @host) ->
    @httpClient = Http.createClient @port, @host
    @sentence = "I am a Client"

  transmit: (request, callback = null) ->
    req = @httpClient.request request.method, request.pathName
    req.end
    console.log "Request sent!"
    if callback
      callback(null, req)
    #req.on 'response', (res) ->
    #  callback(null, res)
      #request.on 'data', (chunk) -> callback(null, chunk)
    #callback(null, request)

And finally, the ‘request’ object.

exports.Request = class Request
  constructor: (@method, @pathName) ->

  method: ->
    @method

  pathName: ->
    @pathname

  responseBody: ->
    @body

  setResponseBody: (body) ->
    @body = body

  appendToResponseBody: (chunk) ->
    @body += chunk

All this is so simple that I really can’t tell why the server doesn’t seem to be working. I’m not even worried, yet, about where the asynchronous code should be to get the information back from the server, but I’d like to figure that out too..

  • 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-25T21:13:54+00:00Added an answer on May 25, 2026 at 9:13 pm

    Ah, you’ve made a classic mistake: You wrote

    req.end
    

    where you meant

    req.end()
    

    So, your request wasn’t actually being sent at all, despite your console’s claims to the contrary! (I see a response.end in your code as well.)

    Incidentally, Vows test code is pretty, but it’s also a complex framework with some subtle gotchas. You may want to try something simpler, like nodeunit.

    Oh, and if you really hate parentheses, you can write do req.end instead of req.end(), but this isn’t a common style.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.