7 ms·
So how do you write a basic web server in CoffeeScript?
by deleo 15y ago
So how do you write a basic web server in CoffeeScript?
- jashkenas 15y agoThe Node.js "Hello World" web server: http = require 'http' server = http.createServer (req, res) -> res.writeHeader 200, 'Content-Type': 'text/plain' res.write 'Hello, World!' res.end() server.listen 3000 console.log "Server running at http://localhost:3000/"
- MostAwesomeDude 15y agoI'm obligated to respond with the same server in Twisted: from twisted.internet import reactor from twisted.web import resource, server class HelloWorldResource(resource.Resource): isLeaf = True def render_GET(self, request): return "Hello, World!" reactor.listenTCP(3000, server.Site(HelloWorldResource())) reactor.run()
- deleo 15y agoOT question. How healthy is the Twisted ecosystem these days? Besides it being stable and been around for years, how does the post-divmod horizon looking? Is the whole stack still being maintained?
- MostAwesomeDude 15y agoAll of the old Divmod team are still hacking Twisted. It's still maintained, everything gets taken care of, and there's really no doubt about Twisted's future.
- deleo 15y agoWell but this isn't written in CoffeeScript. This is what I was saying: CoffeeScript can work alongside Node.js but can't access the filesystem. It might be good in its own right for DOM scripting and such but it doesn't open any more doors than Javascript.
- stdbrouw 15y agoThen what is it written in, if not CoffeeScript. You're somehow very very confused about things :-)
- deleo 15y agoNo I think you are confused. That is Node.js syntax. Ok now show me how you open a file on the filesystem in CoffeeScript then.
- TrevorBurnham 15y ago> CoffeeScript can work alongside Node.js but can't access the filesystem. Um. Node.js gives you access to the filesystem... http://nodejs.org/docs/latest/api/fs.html http://nodejs.org/docs/latest/api/fs.html And anything you can do in Node, you can do from CoffeeScript code running under Node.
- bergie 15y agoQuite a lot of examples of CoffeeScript with Node.js here: https://gist.github.com/978411 https://gist.github.com/978411