Repository navigation
Replies: 1 comment
|
The server is listening. The hang is the event loop.
server.listen(4400, () => {
console.log('listening')
// blocks the event loop — the GET from curl cannot be handled
spawnSync('curl', ['127.0.0.1:4400'], { stdio: 'inherit' })
})Use an async child process (or a timer so the listen callback can finish first): import {spawn} from 'node:child_process'
import {createServer} from 'node:http'
import express from 'express'
const app = express()
app.use(express.static('public'))
const server = createServer(app)
server.listen(4400, () => {
console.log('listening')
const child = spawn('curl', ['http://127.0.0.1:4400'], {stdio: 'inherit'})
child.on('close', () => {
console.log('finish curl')
server.close()
})
})
|
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I'm trying to interact with the server in the
listencallback.Here's the output:
and it just hangs in there forever. I'm expecting it to print out the
curloutput and then stop the script, but the server seems to be not ready for some reason. This also happens with other tools too and not justcurl(curlis just my testing tool here). When I runcurl localhost:4400in the terminal, it works fine. What could be the reason that I can't interact with the server in thelistencallback?All reactions