skip to Main Content

I just started learning JS and have been finding it difficult to run JS code using the node command on the terminal. I’ve tried everything but it doesn’t show anything. Using node command doesn’t show anything

What should I do?

Tried to re-install Node.js a couple of times but it still doesn’t work.

3

Answers


  1. To print something on the terminal, use console.log() instead of alert(). For example, in your case, replace alert(message) with console.log(message) and then it will print on the terminal.

    Login or Signup to reply.
  2. There might be many issues while you try to run the node.js command.
    First reason :- To use alert() you must link your tut1.js with your html file. in script tag.
    second reason : – To print something on the terminal, use console.log() instead of alert(). For example, in your case, replace alert(message) with console.log(message) and then it will print on the terminal.

    third reason:- check your package.json file. check the start key and its value

    code here

    "scripts": {
        "test": "node tut1.js.js",
        "start": "node tut1.js"
      },
    
    Login or Signup to reply.
  3. you can first create a file with names like index.js and enter this text in the terminal
    but each time you run this command you can use nodemon
    he will do it for you.
    link info:[1]: https://nodemon.io/

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search