Home > Back-end >  Express.js doesn't want to listen
Express.js doesn't want to listen

Time:04-06

I'm making a Node.js script where i use express, but listen function is not executing and app doesn't want to listen. I use this code to start express:

var app = require("express")();
app.use(require("express").json())
app.on('error', console.log)
app.listen(3000, () => console.log("Listening at port 3000 "))

By the way, I'm using Windows and I have enabled Node.js into the Firewall. It's strange because I also enabled express logging with set DEBUG=express:* & node index.js and here's the result:

  express:application set "x-powered-by" to true  0ms
  express:application set "etag" to 'weak'  2ms
  express:application set "etag fn" to [Function: generateETag]  1ms
  express:application set "env" to 'development'  1ms
  express:application set "query parser" to 'extended'  1ms
  express:application set "query parser fn" to [Function: parseExtendedQueryString]  0ms
  express:application set "subdomain offset" to 2  0ms
  express:application set "trust proxy" to false  1ms
  express:application set "trust proxy fn" to [Function: trustNone]  1ms
  express:application booting in development mode  1ms
  express:application set "view" to [Function: View]  1ms
  express:application set "views" to 'C:\\Users\\[WINDOWS_USER]\\Desktop\\DiscordBots\\[PROJECT]\\views'  0ms
  express:application set "jsonp callback name" to 'callback'  1ms
  express:router use '/' query  2ms
  express:router:layer new '/'  1ms
  express:router use '/' expressInit  1ms
  express:router:layer new '/'  1ms
  express:router use '/' jsonParser  3ms
  express:router:layer new '/'  2ms
  express:router use '/' <anonymous>  0ms
  express:router:layer new '/'  1ms
  express:router:route new '/XX'  0ms
  express:router:layer new '/XX'  1ms
  express:router:route post '/XX'  1ms
  express:router:layer new '/'  0ms
  express:router:route new '/XXX'  1ms
  express:router:layer new '/XXX'  1ms
  express:router:route post '/XXX'  1ms
  express:router:layer new '/'  0ms

I've tried to use listen at the start of the code, at the end of it, etc. but nothing worked.

CodePudding user response:

The code does not have any problem I think you should first add the path of your node package from program files to path environment of your computer. go to drive c and program files and find node copy the path. and right click on your this pc and right click in properties option and find advance system sitting and environment variables and edit path and add new so past the path on it. it will work.

CodePudding user response:

I'm not sure how and why, but after 5 hours without touching the code now it works. Maybe a temporal bug.

  • Related