Help with another node.js situation

please explain to me the difference between
net.createServer() vs http.createServer()
in node.js
This code is working fine.

var http= require('http');
var fs = require('fs');
var url = require('url');
var writer = require('./database_operation.js');
const server = http.createServer();
console.log("[server]Firing up your servers...");
server.on('connection',function(req,res)
{    
    console.log("[server]Servers are fired up");
	res.writeHead(200,{'Access-Control-Allow-Origin':'*'},{'content-Type':'text/plain'});
	if(url.parse(req.url,true).pathname=="/data.JSON")
	{
		
      res.write(writer.all_data); 
      res.end();
	}
	else{
		res.end();
	}
	
});
server.listen(8080);

But this one is not working although events are fired as expected.

const net = require('net');
const con = require('./database_object.js');
const server = net.createServer();

function connectevent(socket)
{
	console.log(new Date()+"*****connected*****");
    socket.write("Hello");
}
server.on('connection',(socket)=>
{
	console.log("event fired");
	connectevent(socket);
});
server.listen(8080);

image

http is a http server, net is a tcp server

should i use
net.createServer() or http.createServer()

Depends on what you want to build.

Please read the link I provided and the docs for node http module and node net module