gxcn00b
By:
gxcn00b

Node.JS Set up errors

May 2, 2017 477 views
Node.js Ubuntu 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:

module.js:471
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)

2 Answers
gxcn00b May 2, 2017
Accepted Answer

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?
https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-16-04

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
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.

Have another answer? Share your knowledge.