I'm trying create a simple module but doesn't work. Node JS

I’m new to Node JS, on this site and English :)) Sorry for all foreign language problems.

Probably I’m getting a "return" error on this codes. When i add the hi.myFunc(); function i’m getting below following error in terminal:

  if (msg.finished) {

TypeError: Cannot read property 'finished' of undefined
    at write_ (_http_outgoing.js:679:11)
    at write (_http_outgoing.js:661:15)
    at Object.module.exports.myFunc (C:\Users\benom\Desktop\Her Şey\HTML\hi.js:3:9)
    at Server.<anonymous> (C:\Users\benom\Desktop\Her Şey\HTML\app.js:12:16)
    at Server.emit (events.js:315:20)
    at parserOnIncoming (_http_server.js:874:12)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:126:17)

How can i solve this issue?

I got 3 file for this exercise.


const http = require("http");
const fs = require("fs");
const hi = require("./hi.js");

fs.readFile("./index.html", (err, data) => {
    if (err) {
        throw err;
    } else {
        http.createServer((req, res) => {
            res.writeHead(200, { "Content-Type": "text/html; charset=utf8" });
            hi.myFunc(req.url, res.write);


module.exports.myFunc = function (url, res) {
    if (url === "/") {


<!DOCTYPE html>
<html lang="tr">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
        body {
            background-color: rgba(15, 15, 15, .96);
            color: rgb(255, 255, 255);


99 thoughts on “I'm trying create a simple module but doesn't work. Node JS”