0

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

Community
  • 1
  • 1
robinclark007
  • 151
  • 1
  • 1
  • 12
  • seems to be require("util") now http://stackoverflow.com/questions/5227701/wheres-the-documentation-for-nodejss-system-module – loveNoHate Oct 16 '14 at 05:06
  • 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 Oct 16 '14 at 05:29
  • 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 Oct 16 '14 at 05:39

3 Answers3

1

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

dradon
  • 21
  • 1
0

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.

bwight
  • 3,300
  • 17
  • 21
-1

Try:

sudo node test.js

It worked for me