Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node http-server not working on Ubuntu linux

I am trying to run a simple http server in my project directory. All I need is GET request support, so I can GET html/css/js/etc. For that I wanted to use http-server from npm.

I installed it with npm install http-server -g

Now I cd to my project folder where it has the index.html file, I open the terminal and run http-server

But when I open my browser at http://localhost:8080/index.html - it can't connect to the host.

Am I missing something?

like image 248
YemSalat Avatar asked Sep 13 '14 12:09

YemSalat


People also ask

How do I run node js code in Ubuntu?

js and NPM(Node Package Manager) using “sudo apt install nodejs” and “sudo apt install npm” commands respectively. After installation, create a file with the “. js” extension, write Node. js code in it, and execute the file using the “node filename” command.


1 Answers

Okay, the issue was - I had another package installed on Ubuntu, which is also called node

Node JS package is called nodejs on my system and I think that http-server is looking specifically for 'node'. In order to work around this:

I removed the node package with sudo apt-get remove node and created a symlink for nodejs:

sudo ln -s /usr/bin/nodejs /usr/local/bin/node

like image 153
YemSalat Avatar answered Sep 19 '22 05:09

YemSalat