This is the snippet of my code for server.js file. this file imports an http from http module using the ES6 format, it also require url to be able to extract different parts of the url. I have define a variable called pathname and set it equal to url.paerse(req.url).pathname
import { createServer } from 'http';
let url = require("url");
function start(route) {
function onRequest(req,res){
let pathname =url.parse(req.url).pathname;
console.log(`Request for ${pathname} recieved`);
route(pathname);
res.writeHead(200, {"content-type":"text/plain"});
res.write("Good afternoon Paullaster");
res.end();
}
createServer(onRequest).listen(8080);
console.log("Response ready");
}
export { start};
I also have a router.js file that should root request for the extracted path names.
function route(){
console.log(`About to route a request for ${pathname} `);
}
export {route};
Then i have my index.js file where i import all my modules and i use the index.js as the entry point to my application. I'm importing both the start function from server.js file and the require a router from my router.js file.
import {start} from "./server";
let router = require("./router");
start(router.route);
When i run my code i get the following error
```PS C:\Users\paullaster-geek\OneDrive\Desktop\Projects\Dive node> node -r
esm index.js
Response ready
Request for / recieved
ReferenceError: pathname is not defined
at route (C:\Users\paullaster-geek\OneDrive\Desktop\Projects\Dive
node\router.js:2:49)
at Server.onRequest (C:\Users\paullaster-
geek\OneDrive\Desktop\Projects\Dive node\server.js:9:9)
at Server.emit (events.js:314:20)
at Server.EventEmitter.emit (domain.js:486:12)
at parserOnIncoming (_http_server.js:781:12)
at HTTPParser.parserOnHeadersComplete (_http_common.js:119:17)
PS C:\Users\paullaster-geek\OneDrive\Desktop\Projects\Dive node>
You issue is in this function declaration. You should receive
pathnameas a parameter: