What is Neutralinojs?
maingtk-webkit2 on Linux) and implements a WebSocket connection for native operations. This makes applications significantly smaller and less resource-intensive.repository·main·Indexed 42 days ago
https://github.com/neutralinojs/neutralinojs.github.ioDocumentation for the Neutralinojs framework, featuring APIs for application control (app.exit, app.restartProcess), system clipboard management, and comprehensive computer hardware information including CPU, memory, disk, and network interface details. Includes guides on implementing custom native C++ APIs within the framework core.
gtk-webkit2 on Linux) and implements a WebSocket connection for native operations. This makes applications significantly smaller and less resource-intensive.Neutralino.net API allows you to communicate with network resources. Because these methods are implemented at the framework level (C++), they are not subject to webview CORS restrictions, allowing you to make requests to any domain directly from your application.Running neu build generates platform-specific application binaries and a shared resource file in the dist directory.
By default, the build produces two separate files per platform: the application binary and resources.neu. The resources.neu file contains all application resources. For a successful portable distribution, you must include both the specific binary and the resources.neu file for the target OS.
Supported Build Outputs:
| Filename | OS | CPU architecture | Type |
|---|---|---|---|
myapp-linux_x64 | Linux | x86_64 | Application binary |
myapp-linux_armhf | Linux | armhf | Application binary |
myapp-linux_arm64 | Linux | arm64 | Application binary |
myapp-mac_x64 | macOS | x86_64 | Application binary (Intel) |
myapp-mac_universal | macOS | x86_64 and arm64 | Application binary |
myapp-mac_arm64 | macOS | arm64 | Application binary (M1 onward) |
myapp-win_x64 | Windows | x86_64 | Application binary |
resources.neu | all | N/A | Application resource file |
neu buildNeutralinojs provides a built-in shared key-value storage system that acts like a global LocalStorage across all Neutralinojs modes.
All data records are persisted in a .storage directory located at the root of your application. To manually wipe all storage data, you can delete this .storage directory.
For advanced file handling, use Neutralino.filesystem.openFile to create a readable file stream, which returns a file stream identifier (id). You can then use Neutralino.filesystem.updateOpenedFile to perform actions on that stream.
Available actions for updateOpenedFile:
read: Reads a bytes segment (default 256 bytes unless specified in data.size).readBinary: Binary version of read.readAll: Reads until EOF.readAllBinary: Binary version of readAll.seek: Sets the file cursor position (requires data to contain the position).close: Closes the stream.Note: Stream events like data and end are emitted via Neutralino.events.
let fileId = await Neutralino.filesystem.openFile('./myFile.txt');
// Listen for stream events
Neutralino.events.on('openedFile', (evt) => {
if(evt.detail.id == fileId) {
if(evt.detail.action === 'data') console.log('Chunk:', evt.detail.data);
if(evt.detail.action === 'end') console.log('EOF reached');
}
});
// Seek to 10th byte and read 2 bytes
await Neutralino.filesystem.updateOpenedFile(fileId, 'seek', 10);
await Neutralino.filesystem.updateOpenedFile(fileId, 'read', 2);Neutralinojs applications can run in four distinct modes depending on your deployment requirements. The default mode is window.
Neutralinojs restricts arbitrary native API execution for security. To use native functions (like os.*), you must ensure they are included in the nativeAllowList within your configuration file.
Example configuration allowing the os namespace:
"nativeAllowList": [
"app.*",
"os.*",
"debug.log"
]When Neutralinojs spawns an extension, it sends a JSON object via standard input (stdin) containing connectivity details. The extension must use these details to establish a WebSocket connection to the Neutralinojs server.
Connection Details (from stdin):
nlPort: The port of the Neutralinojs server.nlToken: Access token for the native API.nlConnectToken: Token required for WebSocket connection initialization.nlExtensionId: The unique identifier for the extension.WebSocket URL Format:
ws://localhost:{nlPort}?extensionId={nlExtensionId}&connectToken={nlConnectToken}
Native API calls follow a WebSocket-based communication pattern between the JavaScript client library and the Neutralinojs server:
Neutralino.os.getEnv).Neutralinojs can be extended beyond JavaScript using two primary IPC (Inter-Process Communication) methods:
To create a plugin, develop an npm package that exports an index.js file. The CLI uses this file as an interface to register new commands using a register function. The plugin uses a pattern similar to the commander package for defining command strings, options, and actions.
// index.js
module.exports = {
command: 'commandname <action>',
register: (command, modules) => {
command.option('--option1 --option2')
.action((action, command) => {
// your logic goes here..
});
}
}