kitchen-boy / portfolio-generator

Module 9 - Node.js
1 stars 0 forks source link

Title: Generate the HTML file #2

Closed kitchen-boy closed 2 years ago

kitchen-boy commented 2 years ago

Description

kitchen-boy commented 2 years ago

Create a new Git branch:

kitchen-boy commented 2 years ago

9.2.4 Create an HTML Template:

Template Literals - With ES6, we can use a feature called template literals to embed JavaScript expressions into the string. Template literals are enclosed by backticks (`) instead of double or single quotes.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

const generatePage = (userName, githubName) => Name: ${userName}, Github: ${githubName};

Multi-line Strings - Template literals allow us to do easily something that would be difficult with regular strings: multi-line text.

Destructuring Assignment:

const profileDataArgs = process.argv.slice(2, process.argv.length);

const name = profileDataArgs[0]; const github = profileDataArgs[1];*/

const [name, github] = profileDataArgs;

Summary

Completed a function that receives the command-line arguments and inserts them in a HTML template literal.

Next, output this string into a file that can be opened in the browser.

kitchen-boy commented 2 years ago

9.2.5 Generate the HTML File

const fs = require('fs');

*The require statement is a built-in function that's globally available in Node.js. It allows the app.js file to access the fs module's functions through the fs assignment.

fs.writeFile()

fs.writeFile('index.html', generatePage(name, github), err => { if (err) throw err;

console.log('Portfolio complete! Check out index.html to see the output!'); });

kitchen-boy commented 2 years ago

9.2.6 Modularize the Code:

module.exports = generatePage;

const generatePage = require('./src/page-template.js');

Summary: