Software Dev Weekly Update #3: Class Constructors, Node.js, & Modules
Tags: javascript, beginners, node, webdev
Published: 2021-08-11 13:55:31

##This past week was a whirlwind of learning! 

I completed sections #29, #30, #31, then started #32. We wrapped up Class Constructor Functions, covered the setup of GitBash and Node.js, reviewed commonly used terminal/shell commands, created files/directories, learned how to 'export' and 'require' JS files, and more!


**Class Constructor Function**
The 'Extend' and 'Super' keywords demonstrate inheritance between functions by allowing us to remove duplicate code in many different functions and share it from one super function ('extend').

Using 'super' allows us to use part of the super function inside another constructor function when defining new properties.

```javascript
//Pet is a Super class
class Pet {
    constructor(name, age){
        this.name = name;
        this.age = age;
    }
    eat(){
        return `${this.name} is eating!`
    }
}

class Cat extends Pet {
    constructor(name, age, livesLeft = 9){
        //Super allows us to call the constructor in the Super Function called Pet
        super(name, age)
        this.livesLeft = livesLeft;
    }
    meow(){
        return 'MEOWWW!!'
    }
}

class Dog extends Pet {
    bark(){
        return 'WOOOF!!'
    }
    //Dog having it's own Eat method means it will not look for Eat in the Pet function becuase it already found one in the Dog function
    eat(){
        return `${this.name} scarfs their food!`
    }
}
```

*Quick Demo of a [Color Converter Constructor Function](https://github.com/RealNerdEthan/web-dev-bootcamp-2021/blob/2e7867898048a0604f0868c35cd764dbc2d16860/Section%2029%20-%20Prototypes,%20Classes,%20OOP/More_JavaScript_Classes.js)*
![Color Converter Demo](https://i.imgur.com/RCFt9gC.gif)


**My First Brush With Node.js**
Node.js is written with JavaScript but is a beast of its own. We learned that it can be used for all sorts of projects ranging from web servers to [game development](http://www.cross-code.com/en/home), its even used with [Astronauts Spacesuits by NASA](https://openjsf.org/wp-content/uploads/sites/84/2020/02/Case_Study-Node.js-NASA.pdf)!

For the purposes of learning web development we focused on using Node.js as a console to execute JavaScript files we've written. For example, we wrote a program that creates a 'Project' folder and populates it with our boilerplate files (index.html, app.js, styles.css).
```javascript
//File System Module in Node.js example
//https://nodejs.org/dist/latest-v14.x/docs/api/fs.html

//This is required for fs to work
const fs = require('fs');
// console.log(fs);

//This remove the executable file path and the file path to the new folder/file
const folderName = process.argv[2] || 'Project'

//ASync version of making a directory
// fs.mkdir('ASyncTest', { recursive: true }, (err) => {
//     console.log('In the callback!')
//     if(err) throw err;
//   });

//Sync version of making a directory
//fs.mkdirSync('SyncTest');

//console.log('I come after the mkdir in the file!')

//This is an example of how to create a directory and files within it. Also wrapped in a try/catch to catch any errors
try{
    fs.mkdirSync(folderName);
    fs.writeFileSync(`${folderName}/index.html`, '');
    fs.writeFileSync(`${folderName}/app.js`, '');
    fs.writeFileSync(`${folderName}/styles.css`, '');
} catch(error){
    console.log('Ope! An error was encountered:', error);
}
```
**Exploring Modules and the NPM Universe**
In this section we're reviewing the concept of 'export' and using index.js with 'require' to access data from one file inside another.

This lesson is still in progress but it's building to a better understanding of Modules and their key part in modern web apps.

###The learning journey continues...
![studying setup with computer and book](https://images.unsplash.com/photo-1501504905252-473c47e087f8?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=967&q=80)
It's been a fantastic week and I'm very excited to be starting the 'backend' part of the course. Being able to deploy what I've written is the missing piece to the puzzle that I've never been able to solve but I feel it's within reach. It keeps me motivated to push on and I can't wait to share what I've learned next week!

---
I hope you enjoyed the read!

Feel free to follow me on [GitHub](https://github.com/RealNerdEthan), [LinkedIn](https://www.linkedin.com/in/ethan-goddard-a4376952/) and [DEV](https://dev.to/realnerdethan) for more!