How to get Node.JS Express to listen only on localhost?

I have an application that I have behind a reverse proxy, I would like for it to only listen to localhost/ I expected this to work: app.listen(3001, ‘localhost’); or app.listen(3001, ‘’); …but instead I get an error: node.js:201 throw e; // process.nextTick error, or ‘error’ event on first tick ^ TypeError: Cannot read property ‘port’ … Read more

Unable to Change Favicon with Express.js

This is a really basic question, but I’m trying to change the favicon of my node.js/Express app with app.use(express.favicon(__dirname + ‘/public/images/favicon.ico’)); and I’m still getting the default favicon. This is in my app.configure function, and yes, I’ve verified that there is a favicon.ico in the /public/images/favicon.ico.There’s nothing about a favicon.ico in the console, either, which … Read more

How can I get the browser language in node.js (express.js)?

User requests some page and I want to know (on server side) what is the language in his/her browser. So I could render template with the right messages. On client side it’s easy: var language = window.navigator.userLanguage || window.navigator.language Answer You can use req.headers[“accept-language”] to get the language/locale the user has set in his browser. … Read more

Service Worker registration error: Unsupported MIME type (‘text/html’)

I’m using create-react-app with an express server. create-react-app has a pre-configured ServiceWorker that caches local assets ( The problem I encountered when I tried to publish on my server is that the service-worker.js file was available, but I was getting errors in my browser console when it tried to register it. On Firefox, I got … Read more

How do you detect the environment in an express.js app?

How do you detect what environment an expressJS app is running in? (development, test, production?). There’s nothing in process.env indicating an environment… I’m aware that you can declare variables in your configuration file under each environment, but that doesn’t help if you are dynamically loading modules… Answer You can either check the environment by checking … Read more

Reload Express.js routes changes without manually restarting server

I tried express-livereload, but it just reloaded view files. Should I use another tool, or this one can be configured to watch for my index.js file which runs the server? I read that options are the same as node-livereload, and default for watched files include .js files. Any URL you know with a simple configuration? … Read more