Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
179 views
in Technique[技术] by (71.8m points)

javascript - Use "coffee" instead of "node" command in production

I have an app.js that is running express.js.

I wanna convert the code to coffeescript and thought about to create a app.coffee that I compile to app.js so I can run it with "node app.js".

But then it hit me that I could just write that file in app.coffee and run it with "coffee app.coffee".

Is this a better way? Can I run the server with "coffee" in production?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Yes you can use coffee command in production. I use it.

I can see two reasons why you would want to use app.js wrapper.

  1. You want to use local installation of CoffeeScript. (different versions between apps)
  2. You want to use the default npm start to launch your server :) See npm help scripts

Oh, and you don't need compile it. You can use a wrapper like this which compiles the coffee file transparently:

server.js:

require('coffee-script').register();
require("./yourcoffeeapp.coffee");

This wrapper technique is especially useful if you want to use CoffeeScript in some hosted environments that does not directly support the CoffeeScript command. Such as Cloud 9 IDE. No need to fiddle with compiled js-files.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...