Developing widgets: Using Node.js APIs in widgets - Glitter/Glitter GitHub Wiki
Intro
Glitter widgets can make use of the Node.js APIs. This integration is disabled by default because it can be dangerous. Access to Node.js basically allows you to interact with the system in a malicious way that those using widgets might not expect, and potentially cause huge damage.
Enabling Node.js integration
Node.js integration can be enabled in the package.json
file of your Glitter widget. Inside the "glitter"
property, define a new property "nodeIntegration"
which is a boolean, and set its value to true
.
Accessing Node.js APIs
To access native Node.js APIs, use window.require
instead of import
or require
. Example:
const fs = window.require('fs');
fs.readdir(__dirname).then(...)
Using Node.js libraries inside widgets
The current implementation only allows access to the native Node.js APIs. Trying to install and make use of Node.js specific modules from NPM might work, but is not officially supported. Support for it will come later as the current implementation will not work for distributing the widgets.