Coffee-Script Connect/Express Middleware
raw JSON →iced-coffee-middleware (also known as `coffee-middleware`) is a Connect/Express middleware designed for on-the-fly compilation of CoffeeScript files (`.coffee`) into JavaScript. Currently at version 0.2.1, it provides functionality to dynamically serve compiled JavaScript, offering options such as `force` for continuous recompilation, `bare` for compilation without the top-level safety wrapper, and `encodeSrc` for embedding base64 source maps. This package leverages patterns from `less-middleware` and is built for integration with older `connect` and `express` versions that utilized `createServer()` and `app.configure()`. Due to its reliance on these long-deprecated APIs and the declining prevalence of CoffeeScript in new web development, the package's active maintenance and applicability to modern Node.js ecosystems are highly questionable. Its development cadence is effectively halted, with no significant updates in many years, making it primarily a historical artifact rather than a viable solution for contemporary projects.
Common errors
error TypeError: app.createServer is not a function ↓
npm install express@3.x) or refactor your application to not use this legacy middleware. error Error: Cannot find module 'coffee-middleware' ↓
npm install coffee-middleware (or npm install iced-coffee-middleware if that was the intended name, though the readme uses coffee-middleware). Check node_modules and your package.json. error SyntaxError: Cannot use import statement outside a module ↓
const coffeeMiddleware = require('coffee-middleware'); and ensure your file is treated as CommonJS (e.g., no "type": "module" in package.json or rename to .cjs). Warnings
breaking This package relies on `express.createServer()` and `app.configure()` which were deprecated in Express 4.x. It is not compatible with modern Express applications without significant bridging or downgrading Express versions. ↓
deprecated The use of CoffeeScript for new web development projects has largely declined. Modern projects typically use TypeScript or contemporary JavaScript with transpilers like Babel. ↓
gotcha This package is CommonJS-only and cannot be directly `import`ed in an ESM module context. Attempting to do so will result in a runtime error. ↓
gotcha The package is at version 0.2.1, indicating an early development stage and potential lack of stability or extensive testing for production environments. It has not seen updates for many years. ↓
Install
npm install iced-coffee-middleware yarn add iced-coffee-middleware pnpm add iced-coffee-middleware Imports
- coffeeMiddleware wrong
import coffeeMiddleware from 'coffee-middleware';correctconst coffeeMiddleware = require('coffee-middleware');
Quickstart
const express = require('express');
const coffeeMiddleware = require('coffee-middleware');
const path = require('path');
const fs = require('fs');
// Create a dummy public directory and a .coffee file for demonstration
const publicDir = path.join(__dirname, 'public');
const coffeeFilePath = path.join(publicDir, 'hello.coffee');
if (!fs.existsSync(publicDir)) {
fs.mkdirSync(publicDir);
}
fs.writeFileSync(coffeeFilePath, 'console.log "Hello from CoffeeScript!"');
// Note: express.createServer() and app.configure() are deprecated in modern Express.
// This example uses patterns from Express 3.x to demonstrate functionality.
const app = express();
// Mock the old `configure` method for compatibility with the example structure
app.configure = function(fn) { fn(); };
app.configure(function () {
app.use(coffeeMiddleware({
src: publicDir,
bare: true, // Compile without the top-level safety wrapper
compress: true, // Example option (may require 'uglify-js' in older versions)
force: true // Ensure recompilation on each request for demo
}));
// Serve static files, ensuring compiled JS files can be accessed
app.use(express.static(publicDir));
});
const PORT = 3000;
app.listen(PORT, () => {
console.log(`Server running on http://localhost:${PORT}`);
console.log(`Try accessing http://localhost:${PORT}/hello.js`);
console.log(`(This will compile and serve public/hello.coffee as JavaScript)`);
});
// To run this example, you would typically need to install older versions:
// npm install express@3.x coffee-middleware connect@2.x