jeffbski / wait-on

wait-on is a cross-platform command line utility and Node.js API which will wait for files, ports, sockets, and http(s) resources to become available

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

seems to not work

xenoterracide opened this issue · comments

sorry, am I missing something? wrote this in typescript, it exits immediately. I know the server isn't responding yet, no error but the info logs are output.

import waitOn = require('wait-on')

console.info('start', new Date().toLocaleTimeString())
waitOn(
  {
    resources: ['http://localhost:3000'],
    delay: 10000,
    validateStatus: function (status) {
      console.error(status)
      return status >= 200 && status < 300 // default if not provided
    },
  },
  err => {
    console.error(err)
  },
)
console.info('end', new Date().toLocaleTimeString())

Having the same problem here

Same here

Which Node version are you using?
If greater than 17, Is you server listening to IPv6 or IPv4?

Your code is simply invalid. You are not having any "success" callback that would be called when the http://localhost:3000 finally responds.
What happens right now, waitOn is waiting indefinitely for the resources to be active. Because waitOn is asynchronous, it will be scheduled while the rest of the code would execute. If you add timeout to the options, you would see error callback being called.
e.g.

const waitOn = require('wait-on');

console.info('start', new Date().toLocaleTimeString());
waitOn(
  {
    resources: ['http://localhost:3000'],
    delay: 10000,
    timeout: 1000,
    validateStatus: function (status) {
      console.error(status);
      return status >= 200 && status < 300; // default if not provided
    },
  },
  (err) => {
    console.error(err);
  }
);
console.info('end', new Date().toLocaleTimeString());

Would fail after one second, https://stackblitz.com/edit/node-u9mhgz?file=index.js

If you want to use it either provide success callbacks and timeout or better yet use it with promises.

I have this issue with node v.19. As @metcoder95 hinted, the problem went away after downgrading to 16.18.0

Same for me after upgrading from node 16.x to 18.x

Seems to be related to this issue:

nodejs/node#41625 and this PR nodejs/node#44731

Might be a good idea for wait-on to listen to ::1 / 0:0:0:0:0:0:0:1 as well when it involes localhost

I am also having an issue since updating to Node 18. If I change back to Node 16, it seems to work fine.

Might be duplicate of #109. Try replacing localhost with 127.0.0.1. Worked for me on Node v18.

Might be duplicate of #109. Try replacing localhost with 127.0.0.1. Worked for me on Node v18.

That worked for me perfectly! Thank you!

Might be duplicate of #109. Try replacing localhost with 127.0.0.1. Worked for me on Node v18.

Thank you so much! That worked for me.