You are here:
< Back

Creating Your Own NodeJs Modules

 

With our NodeJs application management system you have the option to create, upload, and run your own nodeJs applications on your server.

When uploading the application you have the option to load the configuration found in the config.json file or overwrite it.

The module should be a .zip compressed file with the following structure:

|—-config //folder contains the configuration file and the images
|     |—-config.json
|     |—-icon.png
|     |__placeholder.png
|
|—-index.js //your main starting nodeJs application file
|__package.json //with the necessary npm packages listed in it

Please do not include the node_modules folder and the package-lock.json file. The system will install the necessary modules automatically.

Please also do not include any other files on any other folder level named the same as one of the required files. Any other file or folder can be included.

The icon and the placeholder image has to be .png image file.

 

The configuration JSON file has to contain:
{
    “name“: {{name_of_the_module, has to be unique and cannot contain special characters or white spaces}},
    “max_memory_restart“: {{The maximum memory usage of the module, like: “100M” for 100 megabites}},
    “description“: {{the description of the module}},
    “query_params“: {{the query parameters of the module, Array of parameter objects}},
    “endpoint“: {{the main route of the application if it has one, like: “/test“}},
    “isWidget“: {{false or true if the module is a widget and should appear in the content editor as a custom element}}
}
See more about Editor integration and the query parameter types here.

The system will automatically assign a PORT number for each module in its environment. This port can change dynamically with every restart.
If your application has web service functionality you need to run it on the PORT read from the environment variable, process.env.PORT .

Example:
var http = require('http');

http.createServer(function (req, res) {
   res.writeHead(200, {'Content-Type''text/plain'});
   res.end('Hello World!');
}).listen(process.env.PORT);
You can download a sample module here.