whatisgithub

What is brain.js?

brainjs/brain.js — explained in plain English

Analysis updated 2026-06-24 · repo last pushed 2024-09-26

14,856TypeScriptAudience · developerComplexity · 2/5StaleSetup · easy

In one sentence

brain.js is a JavaScript neural network library for Node and the browser, with feed-forward, RNN, LSTM, and GRU types and optional GPU acceleration.

Mindmap

mindmap
  root((brain-js))
    Inputs
      Training pairs
      Sequences
      Image vectors
    Outputs
      Predictions
      Classifications
      Forecasts
    Use Cases
      Browser ML demos
      Forecast sequences
      Train small models
    Tech Stack
      JavaScript
      TypeScript
      Node.js
      WebGL
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Train a small feed-forward neural network in a browser tab and run predictions client-side.

USE CASE 2

Forecast a time series with an LSTM that runs inside a Node.js backend.

USE CASE 3

Classify short text snippets or simple images without leaving JavaScript or calling a Python service.

USE CASE 4

Build an in-browser teaching demo that shows training curves and predictions live as users tweak data.

What is it built with?

JavaScriptTypeScriptNode.jsWebGLheadless-gl

How does it compare?

brainjs/brain.jsairbnb/react-sketchappsindresorhus/got
Stars14,85614,87914,903
LanguageTypeScriptTypeScriptTypeScript
Last pushed2024-09-26
MaintenanceStale
Setup difficultyeasymoderateeasy
Complexity2/53/52/5
Audiencedeveloperdesignerdeveloper

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · easy Time to first run · 5min

GPU mode needs the headless-gl native module, prebuilt binaries usually work but a source build needs GLEW and libxi-dev on Linux.

So what is it?

brain.js is a JavaScript library for building and training neural networks, the kind of model that learns patterns from example data. It can run in a normal Node.js server or directly in a web browser, and it can use the graphics card on the machine to speed things up where one is available. The project is a continuation of an older library called harthur/brain that is no longer maintained. The README emphasises that you do not need to leave the JavaScript world to use it. You install it with npm install brain.js, or drop in a script tag from a CDN like unpkg, and you have access to several network types: feed-forward NeuralNetwork, recurrent RNN, LSTM, GRU, time-step variants of those for sequence forecasting, and autoencoders. A short XOR example in the README shows the basic shape of the API. You create a network with a config object that sets things like the number of hidden layer neurons and the activation function, then call net.train with an array of input and output pairs, and net.run to get a prediction for a new input. For GPU acceleration the library depends on a native module called headless-gl. The README explains that prebuilt binaries usually work, but if they fail to download you may need to build from source, which on Linux means installing build-essential, GLEW, libxi-dev, and pkg-config. The full README is longer than what was shown.

Copy-paste prompts

Prompt 1
Train a brain.js NeuralNetwork on the XOR dataset in Node and print the loss curve.
Prompt 2
Use brain.js LSTMTimeStep to forecast the next 5 values of a noisy sine wave in a browser page.
Prompt 3
Wire brain.js into a small Express app where users post training pairs and get a prediction back as JSON.
Prompt 4
Compare brain.js NeuralNetwork accuracy and training time against a TensorFlow.js model on the Iris dataset.
Prompt 5
Enable GPU acceleration for brain.js on Linux, installing headless-gl from source with GLEW and libxi-dev.

Frequently asked questions

What is brain.js?

brain.js is a JavaScript neural network library for Node and the browser, with feed-forward, RNN, LSTM, and GRU types and optional GPU acceleration.

What language is brain.js written in?

Mainly TypeScript. The stack also includes JavaScript, TypeScript, Node.js.

Is brain.js actively maintained?

Stale — no commits in 1-2 years (last push 2024-09-26).

How hard is brain.js to set up?

Setup difficulty is rated easy, with roughly 5min to a first successful run.

Who is brain.js for?

Mainly developer.

Open on GitHub → Ask about another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.