The Wayback Machine - https://web.archive.org/web/20240706035835/https://www.geeksforgeeks.org/how-do-you-run-javascript-script-through-the-terminal/
Open In App

How do you run JavaScript through the Terminal?

Last Updated : 07 May, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

If you want to run a JavaScript script through the Terminal, you’ll first need to make sure you have Node.js installed on your computer. Here’s a simple guide to help you get started:

Steps to run JavaScript script through the Terminal

Step 1: If you haven’t installed Node.js yet, you can download it from the official website: Node.js Downloads.

Step 2: Create a file of your interest with .js extension.

Example: Create a JavaScript file. Name this file as New.js. 

javascript
// Function to add two variables.

const add = (a, b) => {
    return a + b
}
console.log(add(4, 6))

Output
10

Step 3: Open your terminal or command prompt.

Step 4: Use the cd command to navigate to the directory where your JavaScript file is located.

Step 5: Once you’re in the correct directory, run the script using the node command followed by your script’s filename.

node <FileName>.js

JavaScript is best known for web page development but is also used in various non-browser environments. You can learn about JavaScript from the ground up by following JavaScript Tutorial and JavaScript Examples.



Similar Reads

How to Take Input in JavaScript in VS Code Terminal ?
In JavaScript, capturing the user input through VScode Terminal can be done using various methods and approaches. These approaches are readline module, process.stdin, and process.argv. Table of Content Using readline moduleUsing process.argvUsing process.stdinUsing readline moduleIn this approach, we are using the readline module to create an inter
2 min read
How do you run Postman collections using Newman CLI?
Postman is an API(application programming interface) development tool that helps to build, test and modify APIs.  In this tutorial, we will see how to run Postman collections using Newman CLI(Command Line Interface) Prerequisites:Node JS installed in your systemKnowledge about how APIs worksStep 1 : Checking of Node version Newman is built on Node.
2 min read
How to print variable to the terminal in SASS ?
SASS has three methods of providing an output on the terminal or console of the user. Note: The output may vary from implementation to implementation and compiler to compiler. Using @error rule: When writing mixins and functions that take arguments, you usually want to ensure that those arguments have the types and formats your API expects. If they
3 min read
How to Build Simple Terminal like Website using jQuery ?
Terminal is one of the most common tool used by developers. Many applications, frameworks, and even programming languages have more function which can be invoked using command line interface. Most of the computers come with at least one terminal in their operating system with command prompt now most replaced by cross-platform powershell in windows,
4 min read
Create a new Django project in Pycharm using Pycharm Terminal
PyCharm is one of the most popular Python-IDE developed by JetBrains used for performing scripting in Python language. PyCharm provides many useful features like Code completion and inspection, Debugging process, support for various programming frameworks such as Flask and Django, Package Management, etc. PyCharm provides various tools for producti
2 min read
Angular PrimeNG Terminal Component
Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. In this article, we will know how to use the Terminal component in Angular PrimeNG. We will also learn about the properties, styling along with their
3 min read
Angular PrimeNG Terminal Properties
Angular PrimeNG is an open-source front-end UI library that has many native Angular UI components which help developers to build a fast and scalable web solution. In this article, we will be seeing Angular PrimeNG Terminal Properties. The Terminal Component is a text base UI provided by PrimeNG where we can define our own commands and their output.
3 min read
Angular PrimeNG Terminal Styling
Angular PrimeNG is a UI component library for Angular Applications. It offers many pre-built themes and UI components for a variety of tasks like inputs, menus, charts, Buttons, etc. In this article, we will see how to use Terminal Styling in Angular PrimeNG. The Terminal Component is a text base UI provided by PrimeNG where we can define our own c
3 min read
Axios npm - How to Install Axios npm in Terminal?
Axios is a popular JavaScript library for making HTTP requests in web applications. It simplifies the process of sending asynchronous requests and handling responses. It is commonly used with Node.js and in browser-based projects and can be installed via NPM (Node Package Manager). In this article, we will explore the step-by-step process of instal
2 min read
13 Things You Should Know Before You Enter In Web Development
Every beginner starts their journey in web development learning frontend part, backend part, and some tools which are important to build the web project. Building your first project on your own after so many struggles is an exciting feeling for the beginners. You start having a lot of expectations from your job but when you enter the industry you f
7 min read
three90RightbarBannerImg