Running node.js code just displays a node identifier

前端 未结 9 2184
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-19 19:07

I have the following code in a file called server.js.

var http = require(\'http\');

http.createServer(function (request, response) {
  response.writeHead(200,          


        
相关标签:
9条回答
  • 2021-02-19 19:32

    You can also prioritize in the environments. Steps: Computer -> Right click -> Properties -> Advanced system settings -> Environment variables -> PATH(in system variables list) -> Edit -> Prioritize by moving up

    0 讨论(0)
  • 2021-02-19 19:43

    I used the node.js command prompt, instead of the windows default command prompt and it worked for me. Did not know why it did't work in the windows default command prompt.

    0 讨论(0)
  • 2021-02-19 19:45

    I was also running with same issue - while defining the path for windows use below parameter

    Windows:

    set NODE_PATH=C:\nodejs
    

    OR

    Set the environment variable for nodejs

    NODE_PATH=C:\nodejs
    Path= C:\nodejs
    

    (append the path contain this string “c:\nodejs”)

    0 讨论(0)
  • 2021-02-19 19:50

    Was getting this when I was trying to run cordova commands. Steps to resolve:

    Windows

    1. In CMD prompt, type "where node". As Michael mentioned, this shows you the likely culprit, that you have 2 nodejs EXEs installed on your machine.
    2. Navigate to Start > Computer > Right-click Properties > Advanced system settings
    3. Under the Advanced tab, select Environment Variables
    4. Under System variables, select "Path" variable
    5. Find nodejs EXE, usually "C:\Program Files (x86)\nodejs\"
    6. Cut and paste this to the beginning of the "Path" variable. Ensure the paths are separated by a ";"
    7. Open a new CMD prompt and try cordova again
    0 讨论(0)
  • 2021-02-19 19:50

    This is old, but I ran into this same problem. Exact same message (with my machine name of course). The issue was that there was another node executable on the path, in C:\Program Files (x86)\CA\SharedComponents\PEC\bin. I'm on a windows machine, so running where node showed the two conflicting "node" executables in the path.

    To fix the problem, I just removed the CA directory from the PATH environment variable.

    0 讨论(0)
  • 2021-02-19 19:51

    Don't break your Harvest SCM by removing it from path. Try this one, open your windows command line (cmd) and then pass the following nodejs batch file so that it will set your command line to nodejs environment. Enjoy the node commands there.

    C:> "C:\Program Files\nodejs\nodevars.bat"

    0 讨论(0)
提交回复
热议问题