NodeBB Plugin best practices

Plugin Development
  • I'm thinking it would be good if we establish some best practices for NodeBB plugin development.

    Feel free to contribute by replying and I'll add it to the list.

    • Database keys should start with plugin:[your-plugin-name]: ex: if the plugin is nodebb-plugin-mentions then the database keys would start with plugin:mentions:
    • Use sockets instead of ajax
    • Use CSS transitions instead of jQuery animations, trigger them by toggling classes on the elements
    • Use Bootstrap elements as much as possible or not at all
    • your suggestion here

Suggested Topics

  • A plugin that creates CSS

    Plugin Development
    0 Votes
    10 Posts

    arf doesn't work.

    Possible to update it for last version ?

    @volanar @julian @psychobunny

  • 0 Votes
    4 Posts

    I still have a question. Everything works fine at the moment. Send data from the client to the server isn't a problem now.

    But how can I emit a event to all connected clients serverside?

    Something e.g

    myPlugin.emit('plugins.publishMessage', {data: "Some data"}, function(err, result) { console.log(result); });

    After one hour spending searching different topics and some code I found the solution.

    Besides the custom clientside Sockets

    const myPluginSockets = require.main.require('./src/');

    you have to define the Server Sockets too

    const myPluginSockets = require.main.require('./src/'); const serverSockets = require.main.require('./src/');

    Now you can emit events from server side to the clients:

    serverSockets.server.sockets.emit('messageReceive', data);

    to receive the event clientside, you can use following in ur main.js file:

    socket.on('messageReceive', function(data){ console.log(data); });

    Client console output:
    {msg: "my message"}

    Maybe I'll write a little Tutorial on this because I am probably not the only one who does not understand it so easily.

  • 0 Votes
    3 Posts

    Alternatively, just install it with the --save flag and it will pin the current version in your package.json

    npm install --save sparkpost

  • 2 Votes
    18 Posts

    So now, I have questions to the NodeBB development team. @julian

    About @frissdiegurke 's idea.

    What do you think? Is it secure or do you have any better ideas, policies , plans?

    To manage dependencies between plugin,

    Can we enforce to install and activate plugins by dependencies? Or can we give warnings of wrong configurations, dependencies and so on by plugin on admin UI ( dash board? )?

    Do we have secure way to add/remove/modify custom data by plugin in a filtering pipe?

    For example, on filtering hook, data.pluginData.<plugin name> can be always for plugins (means some sure for core will not use it for different reason!! ), whether they are removed or not after filtering. I know if I select good name( random or highly uniq), then it will be quite safe but it will be better if we have an official space.

    If I want to make a npm module which is dedicated to NodeBB while it's not a plugin, then what is good name for. Maybe nodebb-helper-any-name. It may be for individual plugins.

    I had one more, but I forgot what was it while writing.... 🙂

  • 0 Votes
    1 Posts

    It has been about a year since I develop a nodebb plugin. I would like to get into plugin development again to add a few features to my makerspace community forum. I know that plugin APIs must have changed a bit since then. Is the developer documentation the best place to start looking to get up to date information about the latest patterns and API's we can use? Are there any other resources I should look at that would help me get up to speed again?