From the course: Node.js: Web Servers, Tests, and Deployment

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Building a web server

Building a web server

- [Instructor] One of the coolest things that you can do with Node.js is build web servers. So let's create a simple text server. We're going to import the http module to make that work. We then are going to use the createServer function. Remember, you can always destructure this too. So if you'd rather just select an individual function from the http module, you would wrap it in curly braces and then get rid of the http dot. So from here, we're going to go ahead and pass in our callback function, which takes in a request and a response. Then we're going to write some headers. So we'll say response.writeHead. We're going to say if there's a 200 response, so if everything goes right, we want to specify a Content-Type. And the Content-Type here will just be text/plain. Then we'll say response.end. We'll say Hello World. Perfect. Now, the tricky thing here is we want to chain on another function. So at the end of…

Contents