npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

minoss-example

v0.1.4

Published

Example Module for Minoss

Downloads

3

Readme

Example Module for Minoss

GitHub version NPM version Dependency version

This is an example module to show how to easily create own projects for Minoss and creating own scripts. More information about this can be found in the Minoss documentation.

Table Of Contents


Installation

To install this module to your local Minoss copy just run the following command inside the root directory. It should be instantly available afterwards.

$ npm install minoss-example

Available Examples

This module will install a bunch of example scripts. An overview, by logical order:

  • example.js - basic example of a script
  • error.js - return error messages on execution
  • config.js - access configurations inside script
  • params.js - access url parameters from within a script
  • async.js - example of an asynchronous task

Call an Example

The execution of these example is the same as for every module script. Just call the name of the module and the name of the script by appending it to the request URL.

format:   http://hostname:{PORT}/{MODULE}/{SCRIPT}
example:  http://localhost:8080/example/async

Create an own Module

Creating own modules for Minoss is quite simple. In the main documentation you can find a more technically description. Here we will just create a simple module as tutorial.

1. Create an Module folder

To create a module just crete a folder in the root directory of Minoss, with the name you wish for your module. The name of this folder is the name you later call on request. So, keep it simple and readable.

htdocs/
  |- config/
  |- example/       <-- your 'example' module folder
  |- node_modules/
  |- src/
  |- .jshintrc
  |- gulpfile.js
  |- package.json
  |- README.md
  |- server.js

2. Create a Script file

Inside your new module folder just create a new .js file. The name of this file is the name you later call on request. So, keep it simple and readable too.

htdocs/example/
  |- example.js     <-- your 'example' script file

3. Write your Script

You are free to write everything inside your script you want to. But to have it working with Minoss, you need to export a function. With this in mind, the server can handle everything, even asynchronous tasks.

// always export an executing function with the following parameters:
// - 'config' contains all configuration files for this module
// - 'params' contains the url given parameters
// - 'respond' is a callback function to tell the server the script is finished
// - 'error' is an optional callback you can use to respond errors and failed executions
module.exports = (config, params, respond, error) => {
    // call the 'respond' callback whenever the script is finished
    respond({success: true});
};

The respond callback has two major functions: To tell the server your execution has finished and how it has been finished. Successfully or failed. Beside this you can extend the object with the data you want to respond by the server.

In general you give the respond callback an object as only parameter, containing your data too. Inside this parameter the only needed property is named success, which has to be an boolean. This tells the server that the execution was successfully, or failed.

// pass object
respond({success: true});  // successfull
respond({success: false}); // failed

// shorthand
respond(true);             // shorthand for respond({success: true});
respond(false);            // shorthand for respond({success: false});

To append data to the output just add more properties to the object.

respond({
    success: true,
    hello: 'world',
    foo: 'bar',
});

4. Error Messages as Response

In case of an error you should take care of the conventions. There are basically two ways to respond an error message.

Return Error by response data

Whenever the script got errors while execution the success property should be false. And optional error message should be stored inside error. So you could pass both to the respond callback manually.

respond({
    success: false,
    error: 'the error message'
});

Return Error by callback

A shorter an more readable way is to use error callback, what is the fourth parameter of the script export. With this you can the error message directly to the response. Everything else will be handled automatically.

module.exports = (config, params, respond, error) => {
    error('the error message');
};

Optional: Add a package.json to your Module

If you want to use additional resources (dependencies) in your module, you should use a package.json file to load them. Then node and npm would be able to load al dependencies automatically. You could even add more useful or descriptive informations to this file. A minimal package.json could look somehow like this:

{
  "name": "minoss-project",
  "version": "1.0.0",
  "dependencies": {
    "some-api": "^1.0.0"
  }
}

Make your Module available to others

If you wrote a plugin you may think others could need or want to use too, you should think about to publish it. You would not need much reasources for this. A GitHub account and possible an npm account too.

For this you need a package.json file inside your project. It should contain all information about your module and it's dependencies. You can take a look to the package.json of this module here.

When you have added these file you are ready to publish your module. Create a GiHub account and a repository there and commit it. That's it!

Publish to npm

Even better would it be, if you add your Module also to npm, the package manager of node.js. It is pretty simple too. You just need a account you can register on https://www.npmjs.com. Then you can publish your module with a commandline tool of your choice.

Naming Convention

Only convention for public modules for Minoss is, that the name of the module have to start with minoss-, like minoss-example. This helps to identify such modules and is needed for auto-loading these modules when installed with npm.

Bugs / Feature request

Please report bugs and feel free to ask for new features directly on GitHub.

License

Minoss Example is dual-licensed under MIT and GPL-2.0 license.

Donation

You like to support me?
You appreciate my work?
You use it in commercial projects?

Feel free to make a little donation! :wink: