Skip to content

Simple and Fast Multimedia Library

SFML for Node.js

The Node.js binding for SFML. Create native windows, draw 2D graphics and play audio in JavaScript or TypeScript.

npm install sfml.js

macOS / Windows / Linux

Built on SFML 3.1 · About SFML

The SFML modules

Open a window, draw sprites, play music and exchange data. SFML provides the building blocks for your desktop application.

Module guides

Your first SFML window.

Create a RenderWindow, draw a CircleShape, then display the frame. SFML handles the window and rendering; your JavaScript drives the loop. TypeScript declarations are included.

Follow the quick start

Run this in a graphical desktop session. Escape closes the window; setImmediate leaves room for Node.js I/O between frames.

JS hello.cjsnode hello.cjs
const sf = require('sfml.js');
const win = new sf.RenderWindow(
  new sf.VideoMode(new sf.Vector2u(800, 600)),
  'Hello, sfml.js',
);
const circle = new sf.CircleShape({ radius: 80 });
circle.setPosition(new sf.Vector2f(320, 220));
circle.setFillColor(new sf.Color(108, 190, 82));
win.setFramerateLimit(60);

function frame() {
  win.handleEvents({
    Closed: () => win.close(),
    KeyPressed: e => {
      if (e.code === sf.Keyboard.Key.Escape) win.close();
    },
  });
  if (!win.isOpen()) return;
  win.clear(new sf.Color(24, 28, 32));
  win.draw(circle);
  win.display();
  setImmediate(frame);
}
frame();

SFML examples

Run the examples for graphics, text, shaders, audio recording and networking.

Explore the examples
A running sfml.js Breakout game with green and orange bricks, a ball and a paddle.
breakout.cjsRunning on SFML

Breakout

Breakout, drawn with SFML shapes. Keyboard input and the game loop run in Node.js.

View source
Native SFML render texture example with colored shapes and texture snapshots.
render-texture.cjsRunning on SFML

Draw into a texture.

Use SFML’s RenderTexture as an off-screen target, then display its contents with a Sprite. This running example shows texture composition and captured draw states.

View source

SFML concepts. JavaScript APIs.

Read the SFML C++ documentation alongside the binding’s type reference. Our guides cover promises, shared typed arrays, resource lifetime and batched rendering in Node.js.

Icons made by Lorc, Delapouite & Skoll · game-icons.net · CC BY 3.0