Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Why will node.exe not run sample file where cmd.exe will?

Why will node.exe not run sample file where cmd.exe will?

Problem

I've downloaded and run the latest nodejs .msi for Windows (7), updated PATH (;C:\nodejs), installed nssm and created a service - all's well there hopefully.

Next, I have a sample server.js file from many an online tutorial and have failed to start the nodejs server via C:\nodejs\node.exe. The nodejs terminal opens, and I can input valid javascript, eg: ["a","b"].join() and receive output: "a,b". My sample file is in the same dir as node.exe - but when I input "node server.js", all I get is "...", I must CTRL+C to exit that state.

When I open a Windows cmd prompt, cd C:\nodejs\ and input "node server.js", I receive the expected output from server.js and localhost: 8124 displays the sample message. I then also tried to use npm to install express via node.exe prompt, but couldn't

Why won't node.exe terminal start the sample server, where cmd will?

Problem courtesy of: danjah

Solution

npm is a .exe just like node is. So you cannot run npm inside node since node is not a real shell but kind of a "JavaScript shell". And npm install something is certainly not valid JavaScript.

Solution courtesy of: ThiefMaster

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Why will node.exe not run sample file where cmd.exe will?

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×