Node-Media-Server is an open-source, high-performance, and low-latency live streaming server built with Node.js. The current stable version is 4.2.4. It focuses on providing a robust platform for RTMP (Real-Time Messaging Protocol), HTTP-FLV, and WS-FLV streaming, with enhanced support for modern codecs like HEVC, VP9, and AV1 in its v4 release. This version introduced a comprehensive REST API for management, JWT-based authentication, real-time monitoring, and session management, making it suitable for modern streaming applications. It differentiates itself from alternatives like Nginx RTMP or enterprise solutions by being a Node.js-native, extensible, and lightweight solution ideal for rapid development and integration into JavaScript ecosystems. While it doesn't specify a fixed release cadence, the project shows active development and regular updates.
Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
NodeMediaServer is the default export for programmatic usage in ESM contexts. Direct named imports will typically fail as it's a CommonJS module providing a default export. For CJS projects, `const NodeMediaServer = require('node-media-server');` is correct.
import NodeMediaServer from 'node-media-server';
For TypeScript users, the `Config` interface defines the structure for the server configuration object. It should be imported as a type, not a runtime value.
import type { Config } from 'node-media-server';
While event names are strings, for advanced TypeScript usage, types related to NMS events (like `NmsEvent` or event handler signatures) might be declared in the type definitions and used for strong typing event callbacks. Check the `@types/node-media-server` package for specific event type exports.
import type { NmsEvent } from 'node-media-server';
This quickstart sets up a Node-Media-Server instance with RTMP and HTTP-FLV streaming, a REST API with JWT authentication, static file serving, and stream recording. It also includes basic event logging and environment variable usage for sensitive configuration.
import NodeMediaServer from 'node-media-server';
import * as fs from 'fs';
// Ensure media and html directories exist for recording and static files
const mediaRoot = './media';
const recordPath = `${mediaRoot}/record`;
const htmlRoot = './html';
if (!fs.existsSync(mediaRoot)) fs.mkdirSync(mediaRoot);
if (!fs.existsSync(recordPath)) fs.mkdirSync(recordPath, { recursive: true });
if (!fs.existsSync(htmlRoot)) fs.mkdirSync(htmlRoot);
// Create a dummy index.html for static server to function
if (!fs.existsSync(`${htmlRoot}/index.html`)) {
fs.writeFileSync(`${htmlRoot}/index.html`, '<h1>Node-Media-Server Static Content</h1><p>This is a placeholder page.</p>');
}
const config = {
rtmp: {
port: 1935,
chunk_size: 60000,
gop_cache: true,
ping: 30,
ping_timeout: 60
},
http: {
port: 8000,
mediaroot: mediaRoot, // Directory for recorded files or static content
allow_origin: '*',
api: true, // Enable REST API
api_user: process.env.NMS_API_USER ?? 'admin',
api_pass: process.env.NMS_API_PASS ?? 's3cr3tP@ssw0rd'
},
auth: {
play: false,
publish: false,
secret: process.env.NMS_JWT_SECRET ?? 'superSecretKey!HighlySecure!ChangeMe!',
jwt: {
expiresIn: '1h',
algorithm: 'HS256',
users: [
{
username: process.env.NMS_ADMIN_USERNAME ?? 'admin',
password: process.env.NMS_ADMIN_PASSWORD ?? 'p@ssw0rdF0rAdm1n' // IMPORTANT: Hash this in production!
}
]
}
},
record: {
path: recordPath,
append_file: true // Append to existing file if stream restarts
},
static: {
router: '/static',
root: htmlRoot
}
};
const nms = new NodeMediaServer(config);
nms.on('postPublish', (id, StreamPath, args) => {
console.log(`[NodeEvent on postPublish] Stream started: ${StreamPath}`);
// Example: Log stream details or integrate with other services
});
nms.on('doneConnect', (id, args) => {
console.log(`[NodeEvent on doneConnect] Client disconnected: ${id}`);
});
try {
nms.run();
console.log('Node-Media-Server is running.');
console.log(`RTMP server listening on port ${config.rtmp.port}`);
console.log(`HTTP server with API listening on port ${config.http.port}`);
console.log('Access static files at /static');
console.log('Publish stream via RTMP, e.g., rtmp://localhost:1935/live/streamkey');
console.log('Play stream via HTTP-FLV, e.g., http://localhost:8000/live/streamkey.flv');
} catch (error) {
console.error('Failed to start Node-Media-Server:', error);
}
Upgrade
Version history
Breaking-change detection hasn't run for this library yet.
Audit
Security & dependencies
CVE tracking and dependency tree are planned for a later release.
Agent activity
0 hits · last 30 days
No traffic data recorded yet.