Edis Golubich
Edis Golubich

Reputation: 187

NodeJS Hello World script not running

I've been trying to run a simple Hello World app in node, thing is I'm using console.log to print to stdout instead of using a fancy http server or anything.

I am running NodeJS LTS, node v6.10.0 npm 4.3.0 on Windows 10 x64.

The script I'm running is basically just a console.log("Hello World");.

Now if I run this line from inside the node command line, it works just fine.

But if I try running putting it into a separate file and running it via node program.js where program.js is console.log("Hello World");

So, why I am getting this output:

D:\nodeschool\HelloWorld>node program.js
module.js:471
throw err;
^

Error: Cannot find module 'D:\nodeschool\HelloWorld\program.js'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:394:7)
    at startup (bootstrap_node.js:149:9)
    at bootstrap_node.js:509:3

Oh and the file is definitely there:

     Directory of D:\nodeschool\HelloWorld

    01.03.2017.  18:14    <DIR>          .
    01.03.2017.  18:14    <DIR>          ..
    01.03.2017.  18:04    <DIR>          node_modules
    01.03.2017.  18:14               253 package.json
    01.03.2017.  17:34                27 program.js.txt
    2 File(s)            280 bytes
    3 Dir(s)  627.008.479.232 bytes free

Anyone got any idea?

Upvotes: 0

Views: 2011

Answers (2)

Steven Schobert
Steven Schobert

Reputation: 4269

Based on the output of the dir command, your filename is actually program.js.txt.

So when you run node program.js, it can't find any file named program.js, which results in the error you see.

Rename your file to program.js (without the .txt extension) and try it again.

Upvotes: 1

Bidisha Pyne
Bidisha Pyne

Reputation: 543

It can be either of two case: one your program.js is not in this path D:\nodeschool\HelloWorld\program.js or your node.js installation is not executable in that path. "Try checking chmod of program.js

Upvotes: 0

Related Questions