## TL;DR

Nightwatch talks to a Selenium server that is not running. Start the server (or use direct driver mode), match the host and port in config, and verify with curl.

## Error

```text
Error: Connection refused to selenium server at YOUR_HOST:4444
```

## Steps

1. Check if anything listens: `curl YOUR_HOST/status`. Expected: 200 means it is up and the config is wrong.
2. Start the server: `java -jar selenium-server.jar standalone` or let Nightwatch manage it. Expected: the status endpoint responds.
3. Match `selenium.host` and `selenium.port` in nightwatch.conf.js to reality. Expected: config equals the server.
4. Consider direct driver mode (`webdriver` with chromedriver) to skip the server entirely. Expected: simpler setup, fewer moving parts.
5. Re-run. Expected: Nightwatch connects.

## When to use

- `Connection refused` to the Selenium server at startup.
- Server-based (not direct) setups.

## When not to use

- Assertion failures in running tests.
- Direct driver mode issues.

## Tool compatibility

- Nightwatch 2.x/3.x; Selenium server 4.x.

## Variant phrasings

### Nightwatch ECONNREFUSED the loopback address:4444

The same failure in Node terms.

### Selenium server not running for Nightwatch

Start it or switch to direct mode.

## Why it happens

Nightwatch is a client; without a server there is nothing to talk to. Config drift between the two is the usual cause.

## Edge cases

- Java version matters for the server jar; check compatibility.
- Grid URLs differ from standalone; use the right path.
- Direct mode removes the server but needs the driver binary managed.

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_VBfjFxOPM0A-IEO3FBvgxw
