npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

rpi_camera_livestream

v1.0.3

Published

Using NodeJS and Raspberry Pi camera module to provide a livestream for your website.

Readme

Raspberry Pi Camera Livestream

Using NodeJS and Raspberry Pi camera module to provide a livestream for your website. Forked and improved version of caseymcj's raspberrypi_node_camera_web_streamer. This project is up-to-date and works with the latest Raspberry Pi OS 11 (Bullseye).

Installation

First make sure the legacy camera support is enabled using sudo raspi-config and then select 3 Interface Options.

Install via npm

Create a new project with

npm init -y

and after that, install this package with

npm install rpi_camera_livestream

Install via git

Clone this repository with

git clone https://github.com/RootDev4/rpi_camera_livestream.git

and install the dependencies with

npm install

Quick start

The following snippet automatically starts an express webserver and continuously streams the captured video frames from the Raspberry Pi camera module via the default route /live.stream

Server

const livestream = require('rpi_camera_livestream')

livestream.start()

Client

<img src="http://<your_server_ipaddr>/live.stream">

or just open http://<your_server_ipaddr>/live.stream in your browser.

Basic usage

const livestream = require('rpi_camera_livestream')

livestream.setVerboseMode(true)     // enable verbose mode
livestream.setPort(3333)            // set webserver port
livestream.setPathname('/webcam')   // set route/pathname
livestream.start().then(url => console.log(`Livestream started on ${url}`))
// > Livestream started on http://<your_server_ipaddr>:3333/webcam

Controls

const livestream = require('rpi_camera_livestream')

livestream.start()  // Starts livestream and returns livestream URL
livestream.pause()  // Pauses a started livestream
livestream.resume() // Resumes a paused livestream
livestream.stop()   // Stops a started livestream

All controlling methods are promise-based and hence await'able and then'able

const livestream = require('rpi_camera_livestream')

livestream.start().then(url => {
    console.log(`Livestream started on ${url}`)

    livestream.pause().then(() => {
        livestream.resume()
    })
})

await livestream.stop()

Get last frame

Returns the last captured frame as buffered value. If no images have been captured (which may be the case if no users have connected yet), this value is null.

livestream.getLastFrame()

Take snapshot

Takes a snapshot by using the last captured frame if it is not null and returns it as a base64 encoded image string based on the encoding type you set.

livestream.getSnapshot()

Get supported encoding types

Returns a comma-separated string list containing the supported encoding types.

livestream.getSupportedEncodingTypes()

Socket.io support

Server

First install Socket.io with npm i socket.io

const livestream = require('rpi_camera_livestream')
livestream.start()

// Web socket
const http = require('http').Server(livestream.server.app)
const io = require('socket.io')(http)

io.on('connection', socket => {
    console.log('User connected to socket')
    livestream.camera.on('frame', data => socket.emit('stream', data))
})

// Start HTTP server
// IMPORTANT: use http.listen() and NOT app.listen()
const port = livestream.server.port
http.listen(port, () => console.log(`Server is up and listen on port ${port}`))

Client

<img id="webstream" width="800" height="600">

<script src="https://cdn.jsdelivr.net/npm/[email protected]/client-dist/socket.io.min.js"></script>
<script>
    const bufferToBase64 = buffer => {
        const bytes = new Uint8Array(buffer)
        let binary = ''
        for (let i = 0; i < bytes.byteLength; i++) binary += String.fromCharCode(bytes[i])
        return `data:image/png;base64,${window.btoa(binary)}`
    }

    const socket = io()
    const image = document.getElementById('webstream')

    socket.on('stream', data => image.src = bufferToBase64(data))
</script>

Documentation

Verbose mode

Enable/Disable verbose mode. Default: disabled

livestream.setVerboseMode(true)

Register a running express webserver

Register an express webserver, if you want to use your already running webserver

const livestream = require('rpi_camera_livestream')
const express = require('express')
const app = express()
const port = 8080

livestream.register(app, port)
livestream.start()

app.listen(port, () => console.log(`Webserver listening on port ${port}`))

Set webserver port

Default: 8000

livestream.setPort(3333)

Set route/pathname

Default: /live.stream

livestream.setPathname('/webcam')

Set video width

Default: 1280px

livestream.setWidth(800)

Minimum width is 32px. Maximum width depends on your camera version (v1: 2592px, v2: 3280px). Specify your camera version if necessary (default: v2)

livestream.setWidth(800, 1) // v1 camera

Set video height

Default: 720px

livestream.setHeight(600)

Minimum height is 16px. Maximum height depends on your camera version (v1: 1944px, v2: 2464px). Specify your camera version if necessary (default: v2)

livestream.setHeight(600, 1) // v1 camera

Set FPS

Default: 16

livestream.setWidth(25) // min: 1, max: 90

Set encoding type

Default: JPEG (hardware accelerated)

livestream.setEncoding('PNG')

Valid encoding types are: JPEG, GIF, PNG, PPM, TGA, BMP

Set quality

Default: 25

livestream.setQuality(15) // min: 1, max: 100

Lower values lead to a faster stream.

To-Do

  • Add SSL support

License

MIT