Reputation: 9649
server1.coffee
http = require 'http'
http.createServer (req, resp) ->
resp.writeHead 200
resp.end 'Hi !'
.listen 1337, '127.0.0.1'
server2.coffee
require 'http'
.createServer (req, resp) ->
resp.writeHead 200
resp.end 'Hi !'
.listen 1337, '127.0.0.1'
server1.coffee worked but why did server2.coffee get the error below,
TypeError: Object http has no method 'createServer'
Upvotes: 0
Views: 61
Reputation: 9260
It chains on 'http'
, which is a string
.
You'd need parentheses around the whole require 'http'
expression if you want it evaluated properly in chaining syntax.
Upvotes: 2