Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
217 views
in Technique[技术] by (71.8m points)

sails.js - Using Waterline model outside SailsJS api

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...