I’ve passed all tests in Setting up a server, but at Step 5 (after successfully typing ‘node app.js’), when I press ‘Check work’, the Step 5 green tick won’t appear - the spinner just keeps going round and round. Therefore I cannot move on to Step 6.
What could the problem be? I’m tearing my hair out, because I know I’ve passed the test because the correct result appears in the terminal.
Thanks.
Here is my code:
const http = require('http'); // Creates server instance const server = http.createServer((req, res) => { // Write server code here const { method } = req; switch(method) { case 'GET': return handleGetRequest(req, res); case 'POST': return handlePostRequest(req, res); case 'DELETE': return handleDeleteRequest(req, res); case 'PUT': return handlePutRequest(req, res); default: throw new Error(`Unsupported request method: ${method}`); } }); const handleGetRequest = (req, res) => { const pathname = req.pathname if (pathname === '/users') { return res.end(JSON.stringify(pathname)); } } // Starts server listening on specified port server.listen(4001, () => { const { address, port } = server.address(); console.log(`Server is listening on: http://${address}:${port}`); });