JS command line


Javascript is usually a client side script embedded in a browser. However, javascript can also be run from the command line through node.js.

node.js can be installed on many types of Linux/Unix machines, as well as computers running windows. For questions such as installation, build, development etc please check here. Here we will use windows system as an example.

First download the windows installer from here. Click the installer to install:



To run node.js from command line, just type node:



Suppose we have a javascript file test.js:

var i=8;
var j=10;
var x=i+j;
console.log(x);


To run a javascript file such as test.js, just type node test.js at the command line:



Please note there is no semicolon (;) at the end of the command.


endmemo.com © 2024  | Terms of Use | Privacy | Home