Create a plugin!


  • Swedes

    @julian Is this the newest way to write a plugin!

    I get confused because i see code that uses

    plugin.load = function (data, next) { ...

    If writing plugins for the v1.x.x branch what documentation should I use to write updated code ?

    EDIT:
    I guess this is a better start: https://github.com/NodeBB/nodebb-plugin-quickstart

    module.exports is a node.js thing right. Is it obsolete to use this? Should I only use plugin.load ?


  • Admin

    Easiest (and most up-to-date) way would be to fork quickstart and make your own plugin :smile:


  • Community Rep

    Yes, you always need a module.exports or exports, otherwise, NodeBB will not see your hooks.

    You can see at the end quick-start adds module.exports = plugin

    FYI, you can shorten

    var plugin = {}
    
    plugin.load = function () { ... }
    plugin.stuff = function () { ... }
    
    module.exports = plugin
    

    to just

    exports.load = function () { ... }
    exports.stuff = function () { ... }
    

    I find this syntax more convenient depending on the plugin complexity.


  • Swedes

    @yariplus Nice short, I will try to update my plugin to the new style :)

    Is it easy to read a json file from disk when you visit a page, Lets sat that you have somthing in stuff.json and that file is updated now an then on the disk.


Log in to reply
 

Looks like your connection to NodeBB was lost, please wait while we try to reconnect.