2

I created a new folder on my desktop and in that folder I put a file named app.js containing the following code.

function sayHello(name) {
    console.log("Hello" + name);
}

sayHello("Noah")

In the terminal I entered node app.js and was returned the following.

module.js:549
throw err;
^

Error: Cannot find module '/home/noah/app.js'
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:191:16)
at bootstrap_node.js:612:3

I followed a Digital Ocean tutorial to get everything installed and everything worked as described. Am I putting my files in the wrong location?

3
  • 2
    To run node app.js command, you should be in the same folder where app.js is present. Use ls command to check if app.js file is present under the folder. Commented Sep 5, 2018 at 4:28
  • 3
    You should cd into folder on desktop that contain app.js. Commented Sep 5, 2018 at 4:30
  • Thanks I am relatively new to Ubuntu, but that was my issue. Commented Sep 5, 2018 at 4:36

3 Answers 3

2

try this in your terminal

$ cd /home/noah
$ node app.js

or second option

$ node /home/noah/app.js

I prefer the first option. Good luck.

Sign up to request clarification or add additional context in comments.

Comments

0

Open the folder that contains your app.js file and click right mouse button + SHIFT. Then select 'Open command window here' inorder to open your terminal.

In the terminal check your node and npm versions to make sure both are installed correctly in your computer

    $ node -v
    $ npm -v

Then

    $ npm install

to download and install necessary node modules to your app.

Finally try,

    $ node app 

or

    $ node app.js

Comments

0

I was in the wrong directory. Using the desktop on Ubuntu was my problem, I will need to figure out how to store and create my files in the user directory to save myself from using cd frequently.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.