How to run node js file in terminal

The usual way to run a Node.js program is to run the globally available node command (once you install Node.js) and pass the name of the file you want to execute . While running the command, make sure you are in the same directory which contains the app.js file.

  1. Step 1: Save your javascript with . js extension.
  2. Step 2: Open the command prompt.
  3. Step 3: Locate your path where the . js file is saved.
  4. Step 4: To compile the .js file we have to write.
  5. Node .js.
  6. Step 5: Press the Enter key.
  7. Output: