NPM Packages
ZyveraWeb includes a pure-JVM npm client that can download and install npm packages without requiring Node.js or shell access.
How Package Installation Works
- The plugin reads
package.jsonfrom each Node.js project. - It fetches package metadata from
https://registry.npmjs.org. - It resolves version constraints (
^,~, exact versions,latest). - It downloads the package tarball and extracts it to
node_modules/. - It recursively installs transitive dependencies (up to 3 levels deep).
Auto-Install on Startup
When the web server starts, the plugin automatically installs dependencies for all configured Node.js projects:
[ZyveraWeb] Installing npm packages for demo...
[ZyveraWeb] Downloading lodash@4.17.21...
[ZyveraWeb] Downloading express@4.18.2...
[ZyveraWeb] npm install complete for demo
This runs asynchronously so it does not block server startup.
Manual Installation
From in-game or console:
/zyveraweb node install <project-name>
This is useful for:
- Re-triggering installation after modifying
package.json - Installing dependencies for projects added after initial startup
Listing Installed Projects
/zyveraweb node list
Output:
Node projects:
- demo (installed)
- react-demo (pending)
Using Installed Packages
Once installed, use require() in your server.js:
var _ = require('lodash');
var express = require('express');
function handleRequest(request) {
if (request.path === '/api/users') {
return {
status: 200,
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
users: ['Alice', 'Bob', 'Charlie'],
shuffled: _.shuffle(['Alice', 'Bob', 'Charlie'])
})
};
}
return null;
}
Limitations
- No lockfile —
package-lock.jsonis not used. Versions are resolved at install time from the npm registry. - No lifecycle scripts —
postinstallscripts are not executed. - No native modules — Packages with native (C/C++) addons will not work in the JVM.
- Flat
node_modules— All dependencies are installed in a flat structure (like npm v2). - Maximum depth — Transitive dependencies are resolved up to 3 levels deep.
No comments to display
No comments to display