JavaScript Build a Simple Dynamic Site with Node.js Creating a Simple Server in Node.js Creating a Simple Server

daniel benisti
daniel benisti
11,901 Points

The server running on the console but not in the preview

Hi, my node server is running through the terminal. but when I try to preview I get an error.

const http = require('http');

const hostname = '127.0.0.1'; const port = 3000;

const server = http.createServer((request, response) => { response.statusCode = 200; response.setHeader('Content-Type', 'text/plain'); response.end('Hello World!\n'); });

server.listen(port, () => { console.log(Server running at http://<workspace-url>/); });

I've also tried to copy-paste the exact code from node docs. Thank you

KRIS NIKOLAISEN
KRIS NIKOLAISEN
52,852 Points

What error did you receive?

daniel benisti
daniel benisti
11,901 Points

The problem has been fixed. Thanks.