
brain.js
A JavaScript library for building small neural networks that run in browsers and Node.js.
- Stars
- 14.9k
- Forks
- 1.1k
- Licence
- MIT
- Language
- TypeScript
- Last update
- 2.1 years ago
- Type
- Library
No commits in over a year — check for forks or alternatives before adopting.
What it is
brain.js is a JavaScript library for creating and training neural networks, which are programs that learn patterns from example data. It runs in both web browsers and Node.js, and its description says it is GPU accelerated. It is a continuation of the older harthur/brain project, which is no longer maintained.
- Train a small feed-forward network to classify inputs such as colors into categories, as in the README's color contrast demo
- Train a recurrent network on sequence data and use forecast to predict upcoming values
- Train a network offline and export it with toJSON or toFunction to use on a website
- Stream training data using the Train Stream feature listed in the README
Great for
- JavaScript developers who want to try neural networks without learning a new language
- Developers adding simple pattern recognition, such as classifying inputs, to a web page
- Students learning how neural networks train and make predictions
- Teams that want to train a model offline and then run it in the browser with toJSON or toFunction
Not ideal for
- Large-scale deep learning or research that needs Python tooling and large datasets; the README does not compare performance with other frameworks
- Projects that need the latest model types such as large language models; the README describes only classic network types like feed-forward, RNN, LSTM and GRU
- People who need a guaranteed install on every machine, since the README notes GPU support depends on a native module that may need building from source
How to get it
- 1
Install with a package manager
You'll need: Node.js (version not specified in the README)
Install from npm
npm install brain.js - 2
Run it
- Install the package with npm install brain.js
- Create a network with const net = new brain.NeuralNetwork(config)
- Call net.train() with an array of input and output objects
- Call net.run() with a new input to get a prediction
- 3
Get the most out of it
- Use the activation option with values such as sigmoid, relu, leaky-relu or tanh to change how neurons respond
- Set hiddenLayers to change the network's size
- Train offline and use toJSON or toFunction to deploy a trained network in the browser
- Use the Train Stream and Cross Validation features described in the README for larger workflows
Downloads
Strengths
- Simple API: create a network, call train with an array of input and output pairs, then call run
- Works in both browsers and Node.js, with a CDN script option for quick use
- Has a documented set of network types and training options, plus examples and a demo site
Trade-offs
- Installing GPU support depends on the native headless-gl module, which may need Python, compilers or OpenGL drivers when prebuilt binaries are unavailable
- Training is described in the README as computationally expensive, so it is best done offline or in a worker
- Per the README it is a continuation of an unmaintained project, and the latest release shown is from a repository last pushed in September 2024
How it compares
| Project | Stars | Type | Level | Updated | Best for |
|---|---|---|---|---|---|
| brain.js (this) | 14.9k | Library | beginner | 2.1 years ago | JavaScript developers who want to try neural networks without learning a new language |
| mocha | 22.9k | Library | intermediate | 5 days ago | JavaScript and Node.js developers who want automated tests for their code |
| turndown | 11.5k | Library | beginner | 19 days ago | Developers who need to convert HTML content, such as web pages or rich text editor output, into Markdown |
| next.js | 143k | Framework | intermediate | 4 days ago | Developers already comfortable with React who want a full framework around it |
| debug | 11.5k | Library | beginner | 23 days ago | Node.js developers who want named, toggleable log output instead of plain console.log calls |
| page-agent | 29.6k | Library | intermediate | 6 days ago | Developers adding an AI copilot to their own web app |
Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.