0

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"
stukennedy
  • 1,088
  • 1
  • 9
  • 25

3 Answers3

1

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.

Marius Kjeldahl
  • 6,830
  • 3
  • 33
  • 37
1

try:

#app.coffee
require('zappajs').run port, host,  ->
  @include './routes'

#routes.coffee
@include = ->
  @get '/': ->
    @render 'index.jade',
      foo:'bar'
malix
  • 3,566
  • 1
  • 31
  • 41
0

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' 
stukennedy
  • 1,088
  • 1
  • 9
  • 25