Remember that Express middlewares are just functions, so as long as the function is required it can be used.
user_routes.coffee
hello_user = ( req, res, next ) ->
res.json {"message": "hi"}
module.exports = {
hello_user : hello_user
}
app.coffee
user_routes = require './user_routes'
app.post '/signup', signup.inputsOK, signup.userIsNew, signup.createUser, allowUser, user_routes.hello_user
I would do the middleware setup like this: the app.coffee file is responsible for setting up the route with the middlewares and the actual business logic function... then all the last function needs to do is the actual work required. (This also makes the function easier to unit test, without having to fake out Express routing)
Alternatively with a little work you could separate out the routes and have each file do the app.add work. (I dislike this approach, but many apps do this).
user_routes.coffee
setupUserRoutes = (app) ->
app.post '/signup', signup.inputsOK, signup.userIsNew, signup.createUser, allowUser, (req, res) ->
res.redirect '/'
module.exports = setupUserRoutes
app.coffee
app = express()
require( './user_routes' )(app)
Here you're passing the Express object around to each new module you import. Since you set you exports to be only the one function - which takes one parameter, the created Express object - you can create your routes with the required middleware