robinclark007
robinclark007

Reputation: 151

Node.js doesn't work on Amazon EC2 Ubuntu 14.04 server?

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

Upvotes: 0

Views: 1250

Answers (3)

user3228110
user3228110

Reputation: 1

Try:

sudo node test.js

It worked for me

Upvotes: -1

bwight
bwight

Reputation: 3310

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.

Upvotes: 0

dradon
dradon

Reputation: 21

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

Upvotes: 1

Related Questions