//const https = require('node:https')
const http = require('http')
const fs = require('fs')
const url = require('url')

let server = http.createServer((request, response) => {
	let rUrl = request.url
	console.log(url.parse(rUrl))
	// read file
	fs.readFile('index.html', (err, data) => {
		// if reading failed return error
		if (err) {
			response.writeHead(404)
			response.end('file not found')
		}
		// otherwise return file content
		else {
			response.writeHead(200, {
				'content-type': 'text/html; charset=utf-8'
			})
			response.end(data)
		}
	})

})

server.listen('8080')

