LoginSignup
26
27

More than 5 years have passed since last update.

express.js 4をCoffeeScriptで開発できるようにする

Last updated at Posted at 2014-04-22

いつの間にかexpress.jsも4です。

では早速

expressのインストール

4からnpmではexpressをインストールするんじゃなくてexpress-generatorをインストールするようになりました。

npm install -g express-generator coffee-script js2coffee

プロジェクトの作成

適当な名前のプロジェクトを作成 オプションはお好みで

express hoge -css stylus

cd hoge

ここでjsをcoffeeにする便利ツールjs2coffeeを使い一括で変換

find . -type f -name "*.js" | while read f; do js2coffee "$f" > "${f%.*}.coffee"; done

上手くできたらjsファイルは削除

find . -type f -name "*.js" | xargs rm -f

npm install の前にやらないとnode_modulesの中もcoffeeに代わるので注意

npm install

npm install coffee-script --save

エディターで bin/wwwを編集

 #!/usr/bin/env node
-var debug = require('debug')('my-application');
+require('coffee-script/register');
+var debug = console.log //require('debug')('my-application');
 var debug = require('debug')('my-application');
 var app = require('../app');

これでbin/wwwを直接またはnode-devから実行すればOKです。

疑問

var debug = require('debug')('my-application');

がデフォルトでありますけど これいったいなんなのかよくわからないんですよね。

追記: 2014/5/7
DEBUG=my-application ./bin/www
で起動するとLogが出るんですね(ちゃんと出力を読めよと言う話)

26
27
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
26
27