What is TensorFlow.js

Logo by TensorFlow

Hey, My Name is Rajdeep Singh. in this article, I’m discussing TensorFlow.js. Start the learning Base on some questions. What is Tensorflow.js, How it uses, and why use it?

Let’s start it -

What is Tensorflow.JS?

TensorFlow.js is a library for machine learning.TensorFlow.js create by the google developer team in 2011, but the library was open-sourced in 2015 under the Apache License.

How does it use?

Tensoflows.js very-very simple to use, really yep. When use Tensorflow.js is on your new and old project.

Two ways to use it

  1. HTML Script Tag
  2. Node.js

1.HTML Script Tag

use the HTML script tag on the head tag. Simple Copy on the Fens Tensoflows.js after past in the Head Tag or body Section base on your requirement and use it.

Example: Script Tag

<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@1.0.0/dist/tf.min.js"></script>


when using Node.js to install Tensoflow.js

Simple use Two-step

  1. Go to Node.j's official website. It Is after Install The node on your machine or Laptop.
  2. After install Node, go to tensoflow.js Website Copy Command on the official website after past on your laptop Terminal and install tensoflow.js

A command for node.js and yarn

yarn add @tensorflow/tfjsnpm install @tensorflow/tfjs

Example: code for the node

import * as tf from '@tensorflow/tfjs';

// Define a model for linear regression.
const model = tf.sequential();
model.add(tf.layers.dense({units: 1, inputShape: [1]}));

model.compile({loss: 'meanSquaredError', optimizer: 'sgd'});

// Generate some synthetic data for training.
const xs = tf.tensor2d([1, 2, 3, 4], [4, 1]);
const ys = tf.tensor2d([1, 3, 5, 7], [4, 1]);

// Train the model using the data.
model.fit(xs, ys, {epochs: 10}).then(() => {
// Use the model to do inference on a data point the model hasn't seen before:
model.predict(tf.tensor2d([5], [1, 1])).print();
// Open the browser devtools to see the output


HTML tag and Node.js, Which are the Best way to add tensorflow.js in your project.

When using the HTML tag in your project, you use the CDN pathway run code in Browser.

Node.js uses in your project. In that case, you work on the front and backend.

Most I prefer node.js for use in the project.

Note: this is my conclusion base on my requirement. Maybe your requirement is different. but I prefer node.js always follow official Doc


If you learn more about machine learning, please clap it up and share it so that others can find it!

Any suggestion plz write comment full free



Rajdeep Singh, M.Sc. & Technical writer

JavaScript || Reactjs || Nextjs || Python || Rust || Biotechnology || Bioinformatic || Front-end Developer || Author || https://linktr.ee/officialrajdeepsingh