Drkcore

13 07 2011 javascript coffeescript Tweet

node.jsのweb server exampleをcoffee-scriptで書いてみた

今朝は寝坊したせいで朝コードを書く時間があまり取れなかった。

Node.jsのversionが上がっていたのでnvm installをしつつ、coffee-scriptをちょっとさわる

http = require('http');

http.createServer((req, res) ->
  res.writeHead(200, {'Content-Type': 'text/plain'})
  res.end('Hello World\n')
).listen(1337, "127.0.0.1")
console.log('Server running at http://127.0.0.1:1337/')

ちなみに普通にjavascriptで書くとこうなる。

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(1337, "127.0.0.1");
console.log('Server running at http://127.0.0.1:1337/');

普段Pythonで書いてると文の最後の;とか忘れがちなのでcoffee-scriptは良かったりする

About

  • もう5年目(wishlistありマス♡)
  • 最近はPythonとDeepLearning
  • 日本酒自粛中
  • ドラムンベースからミニマルまで
  • ポケモンGOゆるめ

Tag

Python Deep Learning javascript chemoinformatics Emacs sake and more...

Ad

© kzfm 2003-2021