Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

607
Views
(Node.js) Why body description get hyperlink in my code?

I didn't write hyperlink in my body code. However, it get hyperlink linked to last data list('Javascript'). Why <h2>${title}</h2>${description} get hyperlink in my code?

reference image

var http = require('http');
var fs = require('fs');
var url = require('url');

function templateHTML(title, list, body){
    return `
    <!doctype html>
    <html>
    <head>
        <title>WEB1 -${title}</title>
        <meta charset="utf-8">
    </head>
    <body>
    <h1><a href="/">WEB</a></h1>
    ${list}
    ${body}
    </body>
    </html>    
    `;
}

function templateList(filelist){
    var list = '<ul>';
    var i = 0;
    while(i < filelist.length){
        list = list + `<li><a href="/?id=${filelist[i]}">${filelist[i]}</li>`;
        i += 1;
    }

    list = list +'</ul>';
    return list;
}

var app = http.createServer(function(request,response){
    var _url = request.url;
    var queryData = new URL('http://localhost:3000' + _url).searchParams;
    var pathname =  new URL('http://localhost:3000' + _url).pathname;

    if(pathname === '/'){
        if(queryData.get('id') === null){

                fs.readdir('./data', function(error, filelist){
                    //console.log(filelist);
                    var title = 'welcome';
                    var description = 'Hi there';
                    var list = templateList(filelist);
                    var template = templateHTML(title, list, `<h2>${title}</h2>${description}`);
                    response.writeHead(200);
                    response.end(template);
                })
        } else {
            fs.readdir('./data', function(error, filelist){
                //console.log(filelist);
                fs.readFile(`data/${queryData.get('id')}`, 'utf8', function(err, description){
                    var title = queryData.get('id');
                    var list = templateList(filelist);
                    var template = templateHTML(title, list, `<h2>${title}</h2>${description}`);
                    response.writeHead(200);
                    response.end(template);
                });
            });
        }   
    } else {
        response.writeHead(404);
        response.end('Not found');
    };

});
app.listen(3000);
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!