Building a Sails app modularly for reusable code.

93 views
Skip to first unread message

Nicholas Loomans

unread,
Mar 30, 2016, 11:13:43 PM3/30/16
to sails.js
I am in the process of planning out a base system I will be using for dozens of projects. There will be a lot of reused code like galleries, user permission systems, page editing, etc. I would like to make it as easy as possible to keep code up to date across apps in the case that e.g. I find a bug in the gallery module.

I came across this old thread: https://groups.google.com/forum/#!topic/sailsjs/5iKJcrfuvWY which says it isn't possible in Sails and I was wondering if this is still true or if anyone has come up with a way to get it done.

My current thoughts are to have an npm package with the files and then manually create skeleton files inside Sails' folders. e.g. api/models/Gallery.js would essentially be require('nicsgallery/model').

This feels really hacky, and having to add in files manually on install doesn't sound great, but this would mean the actual code is under control of npm and an npm update across all apps would keep everything fresh.

If anyone has any experience trying to tackle this, or any thoughts, I'd love to hear them.

Cory _

unread,
Mar 30, 2016, 11:15:47 PM3/30/16
to Nicholas Loomans, sails.js

Lookup Mike McNeil's machine packs. This will help you tremendously if the reusable code is for API and backend.

If your reusable code is for front end, use npm modules.

Nicholas Loomans

unread,
Mar 31, 2016, 6:04:43 PM3/31/16
to sails.js, beave...@gmail.com
I had a look, but it more looks like a way to package libraries than anything. Is there an example of a Sails model and controller being packaged up? I couldn't find any.

Alberto Souza

unread,
Apr 1, 2016, 2:56:33 AM4/1/16
to Nicholas Loomans, sails.js
Hi Nicholas,


Do one search in npm for others hooks and see how they works: https://www.npmjs.com/search?q=sails+hook

attr,

Alberto Souza
:Programador JS
+Ember.js, Node.js, PHP e Drupal
We.js <- vê lá :)
:Site pessoal

Nicholas Loomans

unread,
Jun 2, 2016, 12:37:37 AM6/2/16
to sails.js, beave...@gmail.com
Wow, this is late but I've just been able to get back to this... crazy busy, but I want to put a 'solution' so if anyone finds this they can get something out of it.

Just wanted to say thanks and while looking for a suitable sails hook package to model my own code off I found: https://www.npmjs.com/package/sails-hook-hookloader

This does exactly what I want so I'll go with that for starters. Thanks!
Reply all
Reply to author
Forward
0 new messages