1

My 2nd day with Ubuntu: Installed NodeJS, ran my first NodeJS example. Got this error in console:

/home/privateuser/nodejsweb/helloweb.js:11
listen(9999);
^
ReferenceError: listen is not defined

at Object.<anonymous> (/home/privateuser/nodejsweb/helloweb.js:11:5)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:929:3

Code:

var http = require("http");

http.createServer(function(request,response)
    {
    response.writeHead(200, {"Content-Type": "text/html"});
    response.write("<html>");
    response.write("<head><title>Node.JS</title></head>");
    respons.write("<body>Hello web</body>");
    respons.write("</html>");
    response.end();
    }),
    listen(9999);

Then I remembered that during install of NodeJS something optional did not work:

$ apt-get install -y build-essential
E: Kon het vergrendelingsbestand '/var/lib/dpkg/lock' niet openen - open (13: Toegang geweigerd)
E: Kan de beheersmap (/var/lib/dpkg/) niet vergrendelen. Heeft u beheerdersrechten?

In English: Could not lock directory and asks about admin rights.

I installed NodeJS according this advice: Cannot find NodeJS in softwarecentre of Ubuntu

Tried to look which program is locking the directory:

$ sudo lsof /var/lib/dpkg/loc 
lsof: WARNING: can't stat() fuse.gvfsd-fuse file system /run/user/1000/gvfs
      Output information may be incomplete.
lsof: status error on /var/lib/dpkg/loc: No such file or directory
lsof 4.86
 latest revision: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/
 latest FAQ: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/FAQ
 latest man page: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/lsof_man
 usage: [-?abhKlnNoOPRtUvVX] [+|-c c] [+|-d s] [+D D] [+|-f[gG]] [+|-e s]
 [-F [f]] [-g [s]] [-i [i]] [+|-L [l]] [+m [m]] [+|-M] [-o [o]] [-p s]
[+|-r [t]] [-s [p:s]] [-S [t]] [-T [t]] [-u s] [+|-w] [-x [fl]] [--] [names]
Use the ``-h'' option to get more help information.
2
  • 1
    tried option mentioned there, but got a bunch of text which i totally do not understand? I will upddate my question with it.
    – Terradon
    Feb 11, 2015 at 16:37
  • Possible duplicate of Permission denied, are you root?
    – karel
    Jul 18, 2020 at 6:16

1 Answer 1

1

From Stack Overflow:

listen is a function that needs to be called on what is returned by createServer

So the comma before listen had to be replaced by a dot.

Secondly a new error came up because of two typos: respons should be response :)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .