2

I have installed node js on my system but when i am going to vs code and running app.js it is opening command prompt for a second and then closing it.

So app.js has only one line of code.

console.log('hello World')

i am going to terminal and typing node app.js , it is not printing anything in the console.

This is absolute beginner question but i cant find a fix anywhere why it is happening.

Aavesh
  • 37
  • 1
  • 6

3 Answers3

3

Let's do it from scratch Just Follow this Steps-

  1. Open VS Code
  2. Create a file (Ctr+n)
  3. Write code console.log("hello");
  4. Save file as app.js
  5. Open Terminal (ctr+`)
  6. run cmd (node app)

Note - make sure you have node install globally You can check by (node -v) and your file app.js is saved

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
Dpk
  • 567
  • 5
  • 16
  • thanks, if you press run or debug in vscode for this the console print happens and gets clear ... so executing the program from cli helps get the print and in case if you want to debug the function code then vscode F5 helps :) – Abdeali Chandanwala Dec 23 '22 at 11:51
1

i faced the same issue, but when I checked, it was due to a missing (< >) symbol in my HTML code while connecting it with my JS file , it can be the same reason, please do check

0

There can be multiple issues as described in other answers. One such reason can be an unsaved file.

Do try save the file before try running the same in VS, can save with CTRL + S, then run

Rajiv
  • 1
  • 2
  • related: [Why don't other programs see the changes I made to a file in VS Code until I save those changes?](/q/76984829/11107541) – starball Aug 27 '23 at 08:04