Archive for September, 2013

actionhero: be careful with the actions

I am playing with actionhero, a framework for NodeJS, and I was having trouble loading a specific action.

My action exported one single variable, in which I added all the required parameters:

exports.users =
name: "users"
description: "My exported action"
inputs:
required: []
optional: []
authenticated: false
outputExample: {}
version: 1.0
run: (api, connection, next) ->
# my code in here
next(connection, true)

But the file won’t load. Following the error trace I realized that when there is a single export in an action, actionhero expects the exported variable to be called ‘action’. So the previous MUST be:

exports.action =
name: "action"
description: "My exported action"
inputs:
required: []
optional: []
authenticated: false
outputExample: {}
version: 1.0
run: (api, connection, next) ->
# my code in here
next(connection, true)

An alternative, is to add a second exports that does nothing, like I did:

exports.fake =
name: "fake"
description: "Fake export to avoid a bug in actionHero"
inputs:
required: []
optional: []
authenticated: false
outputExample: {}
version: 1.0
run: (api, connection, next) ->
api.log 'Fake method'
next(connection, false)

And now everything is working :)
Hope it helps.