0
votes

I setup a ubuntu14.04 server on Amazon EC2 recently, when I install the nodejs using shell:

curl -sL https://deb.nodesource.com/setup | sudo bash -
sudo apt-get install -y nodejs

It says nodejs is already the newest version. In order to check successful Node installation ,I write this in a test.js file

var sys = require("sys");  
sys.puts("Hello World");

when I try

node test.js

I got nothing in the shell.strange..someohelp?

I follow the offical demo

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');

save it as server.js try to run it with node server.js doesn't work...

But it works well in my local ubuntu server machine. So I guess it's may be an Amazon's problem?

I see this thread:

Can't connect to Node web-server hosted on Amazon EC2

and it's not work on my problem too.After I allow all traffic from everywhere on all ports.Still get the same problem.

BTW,I'm using PUTTY to connect to the server.

It's right that ubuntu 14.04 have a diffent version of nodejs.So I download the .tar.gz file from the offical website the unpack it , and run

./configure && make && sudo make install

Then it works for me....

3
seems to be require("util") now stackoverflow.com/questions/5227701/… - loveNoHate
Why not check the version that is currently installed? node --version. Posting that value may also help explain why there was no output from your test.js. - NikhilWanpal
I try node --version but no output in the shell,that't the problem,cause when I try sudo apt-get again.it tells me the nodejs is already installed. - robinclark007

3 Answers

1
votes

node != nodejs. Try running: nodejs test.js

0
votes

The problem is that some versions of Ubuntu including 14.04 need to have a different package installed for nodejs. There is a conflict with the node process and you're not actually run node but some other application.

To resolve the problem install nodejs using sudo apt get install nodejs-legacy. After doing that you should see a version returned if you run node --version.

-1
votes

Try:

sudo node test.js

It worked for me