Javascript Node.js:使用 CoffeeScript 创建一个 Express 项目
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7284657/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Node.js: Create an Express project using CoffeeScript
提问by donald
When I run express app_name, expressjs creates all the folders and files needed. I'm wondering if there's a way to do the same but instead of creating the app.js in JS, it creates in CoffeeScript.
当我运行 express app_name 时,expressjs 创建所有需要的文件夹和文件。我想知道是否有办法做同样的事情,但不是在 JS 中创建 app.js,而是在 CoffeeScript 中创建。
Thanks
谢谢
采纳答案by Jason Miesionczek
Try this: https://github.com/twilson63/express-coffee
试试这个:https: //github.com/twilson63/express-coffee
express-coffee is a template or boiler-plate to get started writing express web applications in CoffeeScript. It comes ready to go with base setup for an Express Web App. It includes a Cakefile that lets you build, spec, and watch your coffeescript as you develop. You hack in the src folder and run cake build to build you server files, write your mocha in your test folder and run cake test or spec to run your test suite. Create your jade views in the views folder and put your public assets in the public folder...
express-coffee 是一个模板或样板,用于开始在 CoffeeScript 中编写 express web 应用程序。它已准备好与 Express Web 应用程序的基本设置一起使用。它包含一个 Cakefile,可让您在开发时构建、规范和观察您的咖啡脚本。你破解 src 文件夹并运行 cake build 来构建你的服务器文件,在你的测试文件夹中编写你的 mocha 并运行 cake test 或 spec 来运行你的测试套件。在 views 文件夹中创建您的 jade 视图并将您的公共资产放在 public 文件夹中...
回答by David Weldon
回答by Trevor Burnham
I don't think there's a command-line tool to do this, but there are plenty of template projects you could start from. In particular, I'd recommend sstephenson's node-coffee-project. It's not Express specific, but you can easily throw Express into the package.json
and create a src/app.coffee
file that looks something like
我认为没有命令行工具可以执行此操作,但是您可以从许多模板项目开始。我特别推荐 sstephenson 的node-coffee-project。它不是特定于 Express 的,但您可以轻松地将 Express 放入package.json
并创建一个src/app.coffee
类似于
express = require 'express'
app = express.createServer()
# TODO: configuration
app.listen 3000
The important thing is to have a Cakefile
that can do the tasks your project needs. For an Express project, you might want to add a task that not only continuously recompiles your CoffeeScript, but also restarts the server every time you change a source file. Here's a gistof a Cakefile I'm using on one of my projects (you'll have to add "watch-tree"
to your `devDependencies).
重要的是有一个Cakefile
可以完成你的项目需要的任务。对于 Express 项目,您可能希望添加一个任务,不仅不断地重新编译您的 CoffeeScript,而且每次更改源文件时都重新启动服务器。这是我在我的一个项目中使用的 Cakefile的要点(您必须添加"watch-tree"
到您的 `devDependencies)。
回答by the-teacher
ExpressOnSteroidsExpress + SCSS + COFFEE SCRIPT
ExpressOnSteroidsExpress + SCSS + COFFEE SCRIPT
clone project and start cake task /path/to/cake dev
克隆项目并启动蛋糕任务/path/to/cake dev
回答by haohello
just found that there is a project called 'zappa' on github that might be helpful to you http://zappajs.org
刚刚发现github上有一个叫做'zappa'的项目可能对你有帮助 http://zappajs.org