Node.JS Set up errors

Posted May 2, 2017 14.5k views
Node.jsUbuntu 16.04

I followed the tutorial for setting up Node.JS. When setting up the ‘Hello World’ app I get the error message:

curl: (7) Failed to connect to localhost port 8080: Connection refused

I have even gone so far as to create a new droplet and start over. Twice.

I decided to go forward with my project anyway and see if I could figure it out as I went along, I am stuck here:

throw err;

Error: Cannot find module 'websocket’
at Function.Module.resolveFilename (module.js:469:15)
at Function.Module.
load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/root/poisontap/backendserver.js:4:43)
at Module.
compile (module.js:570:32)
at Object.Module.extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module.
load (module.js:438:3)

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
5 answers

That is the guide I was using and following it step by step I get stuck at curl command (while on the server)

Hi @gxcn00b

Just to make sure, are you following this guide?

When you do the curl command, you need to run it on the server.

About the missing websocket module, you need to install it into Node.js

npm install websocket
by Brennen Bearnes
Node.js is an open source JavaScript runtime environment for easily building server-side and networking applications. Node.js applications can be run at the command line but this guide focuses on running them as a service using PM2, so that they will automatically restart on reboot or failure, and can safely be used in a production environment.
  • @hansen

    I would love to know how to check this: “If you do not see the proper output, make sure that your Node.js application is running, and configured to listen on the proper address and port”

    The only place I can think of is in

    code #!/usr/bin/env nodejs
    var http = require('http');
    http.createServer(function (req, res) {
      res.writeHead(200, {'Content-Type': 'text/plain'});
      res.end('Hello World\n');
    }).listen(8080, 'localhost');
    console.log('Server running at http://localhost:8080/');```code```

    Which I have written exactly as presented in the guide.

    • Hi @gxcn00b
      (without clicking the Reply or using the @ we sometimes miss a comment, since we don’t get notified otherwise)

      So when you run the ./hello.js - does it say “Server running at http://localhost:8080/” ?

      If yes, then you need to open another window (console/terminal/putty depending on your computers OS) and connect to the server via SSH, then you run the curl http://localhost:8080 from that window.

      If no, then the hello.js file probably created correctly or didn’t have execution rights.

      • @hansen

        that works like a champ, thank you very much (notice my name is n00b)

        • @gxcn00b :-)
          No, but it’s a little difficult to understand that part, since it’s the only place where a tutorial asks you to open a second window and connect again, and run a command. It’s easy to overlook one of the those tiny steps and then it doesn’t play at all.
          If you have further questions or problems, just remember the @ and I’ll try to assist you.

For anyone having an issue of Network Refused I had to re-enable
my firewall with

ufw enable

For whatever reason I think DigitalOcean reset it. Took me two hours. How unprofessional of this company

Me again. I had a network error issue. My expressjs server didnt have the proper host of

'localhost' or better yet '' 


app.listen(port,  () => console.log(`Example app listening on port ${port}!`))

and so even though I could plug the domain name and the port into my browser and even curl and get some data back, internally my client side node app didnt seem to be able to read the correct web address when I said the host to



netstat -plnt

to see what ports are actually being listened to and try using ‘’ for all hosts

and try

app.listen(port, '',  () => console.log(`Example app listening on port ${port}!`))