Reputation: 1133
I have a function declared in a controller but outside of it, so it's a regular method not an action/api.
Let's say it's just does a console.log()
.
I need to access it from a sails service.
I've tried using sails.controllers.user.myFunction()
. UserController being the function but I get 'undefined is not a function'
.
Is there a way to do this?
Upvotes: 1
Views: 281
Reputation: 228
The way I know to do it is like this (depending on where you are getting it your path could change, I put my test in the services folder):
var controller = require('../controllers/UserController.js');
controller.myFunction( );
I hope this helps!
Upvotes: 1