Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can create your own config file in <code>config/</code> folder. For example <code>config/myconf.js</code> with your config variables: </p> <pre><code>module.exports.myconf = { name: 'projectName', author: 'authorName', anyobject: { bar: "foo" } }; </code></pre> <p>and then access these variables from any view via global <code>sails</code> variable.</p> <h3>In a view:</h3> <pre><code>&lt;!-- views/foo/bar.ejs --&gt; &lt;%= sails.config.myconf.name %&gt; &lt;%= sails.config.myconf.author %&gt; </code></pre> <h3>In a <a href="https://gist.github.com/mikermcneil/8513795" rel="noreferrer">service</a></h3> <pre><code>// api/services/FooService.js module.exports = { /** * Some function that does stuff. * * @param {[type]} options [description] * @param {Function} cb [description] */ lookupDumbledore: function(options, cb) { // `sails` object is available here: var conf = sails.config; cb(null, conf.whatever); } }; // `sails` is not available out here // (it doesn't exist yet) console.log(sails); // ==&gt; undefined </code></pre> <h3>In a model:</h3> <pre><code>// api/models/Foo.js module.exports = { attributes: { // ... }, someModelMethod: function (options, cb) { // `sails` object is available here: var conf = sails.config; cb(null, conf.whatever); } }; // `sails is not available out here // (doesn't exist yet) </code></pre> <h3>In a controller:</h3> <blockquote> <p>Note: This works the same way in policies.</p> </blockquote> <pre><code>// api/controllers/FooController.js module.exports = { index: function (req, res) { // `sails` is available in here return res.json({ name: sails.config.myconf.name }); } }; // `sails is not available out here // (doesn't exist yet) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload