DEV Community

Cover image for HOW TO USE JAVASCRIPT IN YOUR IDE WITHOUT BROWSER
Sourabh Singh
Sourabh Singh

Posted on

HOW TO USE JAVASCRIPT IN YOUR IDE WITHOUT BROWSER

JavaScript in IDE

Some time ago it was not possible to use JavaScript without a web browser but, now with the help of Node.js it is possible to use JavaScript inside any IDE or code editor without touching your Web Browser.

Node.js + JavaScript

Node.js and JavaScript

In order to use JavaScript in your code editor or IDE we have to initialise a npm package which can be done by following command in your terminal.

npm init
Enter fullscreen mode Exit fullscreen mode

After executing this command you will be prompted several questions in your terminal where you have to press enter after specifying the answer.

Note:
You can leave the prompt empty and press enter. The terminal will feed the default value as input.

Prompted inputs in the terminal after npm init

Doing so will initialise a package.json file in your folder. which will have all the necessary details of the your package.

package.json after npm init

Using Node.js Packages

In order to use various Node.js Packages you will need to install them first with the following command:

With NPM

npm install <package-name> --save
Enter fullscreen mode Exit fullscreen mode

With Yarn

yarn add <package-name>
Enter fullscreen mode Exit fullscreen mode

After this you need to declare the packages inside your JS file to access all it's features.

For Example let us use the prompt-sync package inside our JS file:
1.Installing the package with Node Package Manager (npm)

npm install prompt-sync --save
Enter fullscreen mode Exit fullscreen mode

2.Declaring a variable to use package's properties

const prompt = require("prompt-sync")();
let name = prompt("Enter Your Name");
console.log(name)
Enter fullscreen mode Exit fullscreen mode

Notes:

  1. require fetches the package from node modules.
  2. prompt takes input from user.
  3. console.log(name) prints the entered value.

Congrats !! you've learnt how to use JavaScript without browser inside your favourite code editor or IDE.

Drop a like if you found this blog helpful and follow me for more of such blogs. 😄😄

Top comments (0)