Score:0

npm http-server not working on ubuntu 20.04.3 LTS

cn flag

I've been using http-server on Windows for years. Today I installed http-server on ubuntu and it does not work. It initializes exactly as it does on Windows. However, I get an error when I navigate to the local website (http://127.0.0.1:8080). This does not happen on Windows. Any idea how to fix this?

clayton@u20:~/hello-pwa-master$ http-server
Starting up http-server, serving ./

http-server version: 14.0.0

http-server settings: 
CORS: disabled
Cache: 3600 seconds
Connection Timeout: 120 seconds
Directory Listings: visible
AutoIndex: visible
Serve GZIP Files: false
Serve Brotli Files: false
Default File Extension: none

Available on:
  http://127.0.0.1:8080
  http://192.168.4.54:8080
Hit CTRL-C to stop the server

[Sun Dec 12 2021 22:12:15 GMT-0700 (Mountain Standard Time)]  "GET /" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36"
_http_outgoing.js:470
    throw new ERR_HTTP_HEADERS_SENT('set');
    ^

Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
    at ServerResponse.setHeader (_http_outgoing.js:470:11)
    at module.exports.ResponseStream.(anonymous function) [as setHeader] (/usr/local/lib/node_modules/http-server/node_modules/union/lib/response-stream.js:100:34)
    at Object.exports.(anonymous function) (/usr/local/lib/node_modules/http-server/lib/core/status-handlers.js:57:7)
    at Readable.stream.on (/usr/local/lib/node_modules/http-server/lib/core/index.js:339:22)
    at Readable.emit (events.js:198:13)
    at emitErrorNT (internal/streams/destroy.js:91:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
    at process._tickCallback (internal/process/next_tick.js:63:19)
Score:0
cn flag

OK, found the solution. Ubuntu 20.04 LTS for some odd reason has node v10 installed (current LTS is v16). This version is several years old.

I had to manually uninstall node, as apt uninstall left many orphans (in /usr/local/bin, /usr/local/share, /usr/local/lib, and ~).

After completely removing v10, I used curl and apt to download and install node v16. A video on the process is here: https://www.youtube.com/watch?v=zVNiJJj0EL4

Now, with V16 installed, http-server works correctly.

What a waste of time! Why does Ubuntu come with such an outdated version of node?!

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.