Tutto Il Web

Main Menu

  • Home
  • Computer networking
  • Web development
  • Web design
  • Internet marketing
  • Web services

Tutto Il Web

Header Banner

Tutto Il Web

  • Home
  • Computer networking
  • Web development
  • Web design
  • Internet marketing
  • Web services
Web development
Home›Web development›HTML Links in Node JS – JavaScript – SitePoint Forums

HTML Links in Node JS – JavaScript – SitePoint Forums

By Julie R. Kelsey
April 18, 2022
0
0

I have a string template literal to dynamically create an html file, but if I try to add a link tag with href in the string and run Node to run the code to create the html file, I get a 404 error because it’s trying to call GET on my HTML string while it’s building the file. Is there a way to include the href=”path/to/something” in the string without trying to get it?


svoltmer1:

launch Node to run the code to build the html file…

Can you show us the code you use to do this?

It was when I added the in the string template element that the node tries to get the styles.css file instead of just writing it to the html document.

const csvFilePath = "csv/FormSubmissions.csv";
const csv = require("csvtojson");

const PdfWriter = require("csv-converter-to-pdf-and-html/modules/PdfWriter");

const path = require("path");
const fs = require("fs");
const fsPromises = fs.promises;

const pdfFilePath = "./Form-Submissions.pdf";

const creatHtmlFile = async (data) => {
  const fileName = "./Form-Submissions.html";
  return await fsPromises.writeFile(fileName, data);
};

// CREATE HTML FROM JSON OBJECT
const createSubmissionHtml = async (JsonObj) => {
  try {
    return `
      
      
          
          Form Submissions
          
          
          
              ${Object.keys(JsonObj).map((key) => {
                let submission = JsonObj[key];
                return `
                  
    ${Object.entries(submission) .map((entry) => { let listItem; const groups = [ "Contact", "Founders", "Progress", "Idea", "Equity", "Legal", "Curious", ]; const [prop, value] = entry; const propertyValue = `
  • ${prop}:
    ${value}
  • `; const sectionGroup = `
  • ${prop}:
  • `; groups.includes(prop) ? (listItem = sectionGroup) : (listItem = propertyValue); return listItem; }) .join("n")}
`; })} `; } catch (error) { console.log(error); } }; csv({ delimiter: ",", }) .fromFile(csvFilePath) .then((JsonObj) => createSubmissionHtml(JsonObj)) .then((html) => { creatHtmlFile(html); PdfWriter.WritePDF(pdfFilePath, html); }) .catch((err) => err.message);

There’s nothing obvious that I can see that would cause Node to do this.

Unfortunately, in the code you posted, there are a few puzzle pieces that I don’t have access to (e.g. FormSubmissions.csv).

Could you:

  • remove all superfluous steps (e.g. PDF generation is probably irrelevant to the problem to be solved)
  • hardcode any missing values ​​in the code (e.g. the CSV file can probably be replaced with a hardcoded file JsonObj variable)
  • Posting enough code that I can reproduce the problem on my PC.

If you can do that, I don’t mind taking a look and helping you figure out why this behavior is happening.



1 like

Related posts:

  1. Daily Deal: The Modern Web Development and MySQL Programming Pack
  2. What special features of Java are useful in web development?
  3. This training collection explores advanced web development techniques
  4. The 7 Best Websites to Learn Online Web Development

Categories

  • Computer networking
  • Internet marketing
  • Web design
  • Web development
  • Web services

Recent Posts

  • Computer Networking Diploma Guide: Everything You Need to Know
  • Future Web Design and Development
  • Internet marketing agency and consultant, Artisan Internet Marketing, moves from Mount Dora to Sanford, Florida
  • Commission sets goal to eradicate racial disparity in Greenville County | Greenville News
  • Nice article on CSS and Mobile: Alistapart – Community – SitePoint Forums

Archives

  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021
  • May 2021
  • April 2021
  • March 2021
  • February 2021
  • January 2021
  • December 2020
  • November 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
  • February 2020
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • June 2019
  • May 2019
  • April 2019
  • March 2019
  • February 2019
  • November 2018
  • September 2018
  • June 2018
  • May 2018
  • April 2018
  • March 2018
  • February 2018
  • January 2018
  • December 2017
  • November 2017
  • June 2017
  • May 2017
  • April 2017
  • February 2017
  • August 2016
  • February 2016
  • November 2015
  • May 2015
  • January 2015
  • October 2014
  • April 2014
  • January 2014
  • September 2013
  • August 2013
  • June 2013
  • May 2013
  • March 2013
  • August 2012
  • Privacy Policy
  • Terms and Conditions