Networking Plugin
Start your server with automatic environment configuration and network exposure via the --host flag.
#Usage
Add the networking plugin at the end of your Elysia chain with .use(networking):
TS
import { networking } from '@absolutejs/absolute';
import { Elysia } from 'elysia';
new Elysia()
.get('/', () => handleReactPageRequest({ Page: Home, index: indexPath }))
.use(networking); // Starts the server: no .listen() neededThe networking plugin replaces .listen(). It reads your environment configuration and starts the server automatically.
#How It Works
When you .use(networking), the plugin handles server startup:
TS
// The networking plugin does everything when you .use() it:
// 1. Reads HOST and PORT from environment variables
// 2. Checks for the --host flag
// 3. Starts the server with the correct configuration
// 4. Logs the connection info
new Elysia()
.get('/', handler)
.post('/api', handler)
.use(networking); // Starts the server1
Reads environment
Gets HOST and PORT from your .env file
2
Checks --host flag
Binds to 0.0.0.0 if --host is passed
3
Starts server
Calls .listen() internally with the correct configuration
4
Logs info
Outputs the server URL and network address
#Environment Variables
The plugin reads HOST and PORT from your environment:
BASH
# .env file
HOST=localhost
PORT=3000
# The networking plugin reads these automatically
# HOST defaults to 'localhost'
# PORT defaults to 3000#The --host Flag
Use the --host flag to expose your server to the network:
BASH
# Run with --host flag to expose to network
bun run src/backend/server.ts --host
# This binds to 0.0.0.0 instead of localhost
# Useful for testing on mobile devices or local network access#Startup Logging
The plugin logs connection information when the server starts. The Network line only appears when the server is exposed with --host:
absolute dev
Server running at http://localhost:3000 Network: http://192.168.1.100:3000
#Full Example
A complete server setup with the networking plugin:
TS
import { Elysia } from 'elysia';
import { prepare, asset, networking } from '@absolutejs/absolute';
import { handleReactPageRequest } from '@absolutejs/absolute/react';
import Home from './pages/Home';
const { absolutejs, manifest } = await prepare();
new Elysia()
.use(absolutejs)
.get('/', () => handleReactPageRequest({ Page: Home, index: asset(manifest, 'HomeIndex') }))
.get('/api/health', () => ({ status: 'ok' }))
.use(networking);