Project Structure
A Node.js project in ZyveraWeb follows a specific directory layout.
Directory Layout
plugins/ZyveraWeb/site/<project-name>/
├── server.js # Backend handler (JavaScript)
├── public/ # Static frontend files
│ ├── index.html
│ ├── style.css
│ └── app.js
├── package.json # npm dependencies
├── node_modules/ # Installed packages (auto-created)
└── ... # Other assets
Key Files
server.js (Optional)
The backend JavaScript handler. Must export a handleRequest(request) function.
function handleRequest(request) {
// Return a response object or null
if (request.path === '/api/hello') {
return {
status: 200,
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ message: 'Hello!' })
};
}
return null; // Fall through to static files
}
public/ (Optional)
A directory of static files served at the root URL. Files here take priority over server.js logic. This is where you put your HTML, CSS, JavaScript, and other client-side assets.
package.json (Optional)
Defines npm dependencies. The plugin reads this file on startup and auto-installs all listed packages.
{
"dependencies": {
"lodash": "^4.17.21",
"express": "^4.18.0"
}
}
How Files Are Served
When a request arrives for a Node.js site, the handler follows this priority:
- Check
public/for a matching static file. - If
server.jsexists, execute it with the request. - If
server.jsreturns a response, send it. - Otherwise, return 404.
This means you can have both a static frontend (in public/) and an API backend (in server.js) in the same project. Static files are served for anything that exists on disk, and the JavaScript handler is invoked for everything else.
Example Projects
ZyveraWeb creates two example projects on first run:
site/demo/— A simple API backend with a vanilla JS frontendsite/react-demo/— An API backend with a React SPA (React from CDN)
No comments to display
No comments to display