Your First Node.js Web Server



In this video I am going to walk you through all the steps necessary to create your very first Node.js web server. We will start at the very beginning with installing Node.js, and end with a fully functioning basic web server that serves HTML documents.

Download Node.js:
https://nodejs.org/en/

More Node.js Tutorials:

Twitter:

GitHub:
https://github.com/WebDevSimplified

CodePen:
https://codepen.io/WebDevSimplified

#Nodejs #WebDevelopment #WebServer

20 thoughts on “Your First Node.js Web Server

  1. const http = require('http')

    const fs = require('fs')

    const port = 3000

    const server = http.createServer(function(req, res) {

    res.writeHead(200, { 'Content-Type': 'text/html' })

    fs.readFile('index.html', function(error, data) {

    if (error) {

    res.writeHead(404)

    res.write('Error: File not found!')

    } else{

    res.write(data)

    }

    res.end()

    })

    })

    —–

    <!DOCTYPE html>

    <html lang="en">

    <head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Document</title>

    </head>

    <body>

    This is HTML

    </body>

    </html>

    _

    but still it is not working?

    localhost has refused the connection.

Leave a Reply

Your email address will not be published. Required fields are marked *