I want to be able to call coffeescript and js functions declared in other files from a zappa app. I can't get it to work at all.
I tried using @include as explained on the zappajs crashcourse ...
but I get
TypeError: Object # has no method 'include'
Here's my test app code:
#app.coffee
require('zappajs') ->
@get '/': -> @include 'call'
and here's the function I'm trying to call in another file.
#call.coffee
@include = ->
"call me"
Haven't tested anything, but it looks like you're mixing up a few things here. I may be wrong, but you should probably either just use require node.js-style require, OR you can use zappa style @include, but mixing them is probably not a good idea until you really understand what @include does.
The zappa crashcourse you link to shows both defining modules and using them, but both places it is done using @include. Based on what you write I believe you can not mix require and @include the way you are trying to do.
try:
#app.coffee
require('zappajs').run port, host, ->
@include './routes'
#routes.coffee
@include = ->
@get '/': ->
@render 'index.jade',
foo:'bar'
Marius is right, I was mixing up require and @include ... I can get this to work, which is really what I was wanting to do (i.e. call a function in another file)
require('zappajs') ->
test = require('./test')
@get '/': -> test.test(@response)
with a file called test.coffee that looks like this
@test = (res) ->
res.send 'hullo'