Pixl Server Daemon Framework

1.0.50 · active · verified Sun Apr 19

Pixl-server is a generic server daemon framework for Node.js, designed to provide a foundational layer for building custom server applications such as web backends. It offers essential services like configuration file loading, command-line argument parsing, and robust logging capabilities out-of-box. The core differentiator is its plug-in component system, allowing developers to extend server functionality with pre-built or custom components (e.g., pixl-server-web for HTTP serving, pixl-server-api for JSON APIs). The current stable version is 1.0.50. Based on the provided release history, it appears to follow a slow, incremental release cadence within its 1.x major version, with initial release 1.0.0. This framework enables developers to quickly set up and manage daemon processes with modular, extensible functionality.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a Pixl-Server instance, integrate the `pixl-server-web` component to serve static files, and handle graceful shutdown. It sets up a basic web server listening on port 8080, serving an 'index.html' from a local 'www' directory.

const PixlServer = require('pixl-server');
const path = require('path');
const fs = require('fs');

// Create dummy directories for demonstration
const logDir = path.join(__dirname, 'log');
const htdocsDir = path.join(__dirname, 'www');

if (!fs.existsSync(logDir)) fs.mkdirSync(logDir, { recursive: true });
if (!fs.existsSync(htdocsDir)) fs.mkdirSync(htdocsDir, { recursive: true });
fs.writeFileSync(path.join(htdocsDir, 'index.html'), '<h1>Hello from Pixl-Server!</h1>');

let server = new PixlServer({
	__name: 'MyWebServer',
	__version: "1.0.50",
	config: {
		"log_dir": logDir, // Use local log directory
		"debug_level": 9,
		
		"WebServer": {
			"http_port": 8080, // Use a non-privileged port
			"http_htdocs_dir": htdocsDir, // Use local htdocs directory
			"http_ip_address": "127.0.0.1" // Explicitly bind to localhost
		}
	},
	
	components: [
		require('pixl-server-web')
	]
	
});

server.startup( function(err) {
	if (err) {
		console.error("Server startup failed:", err);
		process.exit(1);
	}
	console.log(`MyWebServer v${server.__version} started on http://127.0.0.1:8080`);
	console.log(`Serving static files from: ${htdocsDir}`);
	console.log("Press Ctrl+C to stop the server.");
	
	// Handle graceful shutdown
	process.on('SIGINT', () => {
		console.log("\nShutting down server...");
		server.shutdown(() => {
			console.log("Server shut down gracefully.");
			process.exit(0);
		});
	});
} );

view raw JSON →