Using Waterline model outside SailsJS api

倖福魔咒の 提交于 2019-11-27 17:43:50

问题


Is it possible to use models defined within [app-name]/api/models outside api folder?

I have created separate folder in application root, where I placed cron job that should fill my database every hour. I would like to reuse Models defined inside my api folder, but not sure how to do it.

I see that I can do sails.lift inside that cron script but that doesn't seem very nice to me.

Did someone experience something similar? I'm new to node.js, so maybe I'm missing something pretty obvious.


回答1:


If your concern with using sails.lift is that it starts an actual HTTP server that listens for requests, you can use sails.load instead. It will do everything that lift does--including loading hooks and models--except for starting the server.

var Sails = require('sails');
Sails.load(function(err, sails) {
   // At this point you have access to all your models, services, etc.
});


来源:https://stackoverflow.com/questions/24123090/using-waterline-model-outside-sailsjs-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!