Introduction
In the previous section we made a folder named "core" where we putted every thing we needed for our custom plugin.
It's also possible to use multiple Shared Plugins on the same way. Every plugin that we will made will be added to the "plugins" folder. If we want to make a shared plugin named "test1" we will simple add a new folder named test1 into the plugins folder.
In this new plugin everything can be done on the same way as our core plugin.
The main difference between both is that these ones are destinated to be shared between different projects and the core plugin not.
Plugin Classes
Create a new class
We saw previously how to create a new class into a plugin, without extending or inheriting any other super class.
Here we will show you what's the difference between extending or inheriting a class.

Extend an existing class
When you want to extend an existing class from another plugin, in fact you're going to replace this class. Every time someone requires the extended class, your class will be used. If you overwrite some functions of the extended class, your new custom functions will be called when someone call it on the extended class. This is nice when you want to change or add some functionalities to the core-server.
In order to extend a class you will need to change the config file of your plugin. The value attributed to your class name will be the super class that has to be extended. If you want to extend the SiteManager class of your web-server you will put the value "web-server/SiteManager" to your new class into the config.
A global variable named "SuperClass" is automaticly defined into the plugin and represents the extended super class. In our next example we will still work on a project Core plugin. Here you can see an extension of the SiteManager
  {
    "classes": {
        "SiteManager": "web/server/SiteManager"     
    }
}
  class SiteManager extends SuperClass {

    constructor(server) {
        super(server);
        console.log("Our SiteManager has been extended and will log every http request");                   
    }

    handle(req, res) {
        console.log("We just received a new incoming request:", req.url);
        return super.handle(req, res);
    }
}

module.exports = SiteManager;
Inherit an existing class
When you inherit a class, you are not going to replace the superclass like we did previously. But you're going to make a copy of another class and add some functionalities to this new copy. When someone requires the super class, he will still get the functionalities of the super class and not yours. In the next example we will adapt our SiteManager in order to herit to web-server/SiteManager class. If you test any http request again, you will see that it doesn't use your class anymore. This can be used if you have a SuperClass named "pet" by example, with some class heriting from this one named "Cat" and "Dog". The Cat and Dog class doesn't has to be the same one, buy herits from the same super class.
In our config file we will define the SiteManager as a new class and load the superclass manualy in our code.
  {
    "classes": {
        "SiteManager": null  
    }
}
  const SuperClass = plugins.require("web-server/SiteManager");

class SiteManager extends SuperClass {

    constructor(server) {
        super(server);
        console.log("Our SiteManager has been extended and will log every http request");                   
    }

    handle(req, res) {
        console.log("We just received a new incoming request:", req.url);
        return super.handle(req, res);
    }
}

module.exports = SiteManager;
Extending the Api Environment
Every project need different functionalities. When extending the api environment, you will add new methods that can be used inside your api.
A simple example of this could be a password hasher. In the next example we will extend the api environment and add a hashing function.
This hashing function will be used in our login api.
  {
    "classes": {
        "ApiEnvironment": "api/ApiEnvironment"  
    }
}
  class ApiEnvironment extends SuperClass {

    hash(field) {
        //We will takes the field of the post with the given name
        const value = this.post[ fields ];

        //Returns a sha1 hash with the integrated Crypter object
        return Crypter.sha1Hex( value );
    }
}

module.exports = ApiEnvironment;
  this.check_variables("username", "password");

if(this.username !== "test")
    return "wrong password";

return {                           
    hash: this.hash( "password" )
}
Next steps
An Important part when scalling an app is the ability to communicate between the different nodes.
This is why we created a network plugin, that will be explained in the next section.