my host just installed node.js

my host just installed node.js

Problem

he used this tutorial: http://blog.urbaninsight.com/2012/10/31/installing-nodejs-centos-55-server

and apparently it has gone well, 100% good, no errors.

now i am here: http://www.nodebeginner.org/

I can’t fide any instructions on what node modules i need to put on my server so I am guessing … I downloaded the latest node source code from the node site and have put the lib folder into my public_html.

I now have made a hello.js which looks like this:

var http = require("lib/http.js");

http.createServer(function(request, response) {
  response.writeHead(200, {"Content-Type": "text/plain"});
  response.write("Hello World");
  response.end();
}).listen(8888);

and ‘as i expected’ my guess is utter poop.. when I go to mysite.com:8888 i get Oops! Google Chrome could not connect to blaa blaa blaa

I have to think hard of how/what exactly i am trying to ask here…ok, I keep reading tutorials about doing things locally but can find nothing for online, to be honest after my host finished installing stuff I expected to visually see some new .js file(s) sitting on the server (http.js? or something). I actually can’t even figure out how to ask google on this one…

I can look through the tutorials at the code and see that it looks like very easy javascript (my favourite language, better than english), but its like i’m missing the part where i need to upload or connect to the frame work like when you use jquery; you can’t just write jquery code cause the browser will be like what the hell is $? first you must do something like:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

1.use a server that can interpret/run node (done)

2.??!

3.write simple code

—————update—————————–

[root@user node-latest-install]# curl https://npmjs.org/install.sh | sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  7882  100  7882    0     0   2835      0  0:00:02  0:00:02 --:--:-- 7697k
tar=/bin/tar
version:
tar (GNU tar) 1.15.1
install npm@latest
fetching: http://registry.npmjs.org/npm/-/npm-1.2.18.tgz
0.10.3
1.2.18
cleanup prefix=/root/local
find: /root/local/lib/node: No such file or directory
find: /root/local/lib/node: No such file or directory

All clean!
/root/local/bin/npm -> /root/local/lib/node_modules/npm/bin/npm-cli.js
npm@1.2.18 /root/local/lib/node_modules/npm
It worked
[root@user node-latest-install]# cd ~
[root@user ~]# ls -l
total 548
drwxr-xr-x  5 root root   4096 Apr  7 04:03 local
drwx------  5 root root   4096 Apr  4 19:37 Maildir
drwxr-xr-x 10 root root   4096 Apr  7 04:04 node-latest-install
drwxr-xr-x  2 root root   4096 Apr  7 04:04 tmp
-rw-r--r--  1 root root 536584 Apr  4 19:38 virtualmin-install.log
[root@user ~]# ls -l ~/local
total 12
drwxr-xr-x 2 root root 4096 Apr  7 04:04 bin
drwxr-xr-x 4 root root 4096 Apr  7 04:03 lib
drwxr-xr-x 3 root root 4096 Apr  7 04:03 share
[root@user ~]# 

I’ve also changed to require(“http”) and it still is giving me the same ‘oops’ error

Problem courtesy of: Ben Muircroft

Solution

To answer your main question about programming in node in general, you seem to be missing npm

1) First things first, install npm using

curl http://npmjs.org/install.sh | sh

Once you have npm, programming in node becomes much easier.

2) In your file, change

var http = require("lib/http.js");

to

var http = require("http");

Everything should work fine then.

Solution courtesy of: Niall

Discussion

Leave a Reply

Your email address will not be published. Required fields are marked *