HOW TO USE JAVASCRIPT IN YOUR IDE WITHOUT BROWSER
Sourabh Singh
Posted on January 22, 2023
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 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
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.
Doing so will initialise a package.json file in your folder. which will have all the necessary details of the your package.
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
With Yarn
yarn add <package-name>
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
2.Declaring a variable to use package's properties
const prompt = require("prompt-sync")();
let name = prompt("Enter Your Name");
console.log(name)
Notes:
- require fetches the package from node modules.
- prompt takes input from user.
- 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. ππ
Posted on January 22, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
October 21, 2024