Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 43 additions & 28 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ As we work together on this during class, I would encourage you to make comments

## Core Learning Objective

* Use NodeJS APIs to interact with files and the web
- Use NodeJS APIs to interact with files and the web

## Sub-Objectives

* Setup a basic NPM project
* Run your project from the command line with scripts
* Export and require your own files
* Require and use core Node libraries
* Install, require, and use packages from the web
- Setup a basic NPM project
- Run your project from the command line with scripts
- Export and require your own files
- Require and use core Node libraries
- Install, require, and use packages from the web

### Prereqs

Expand All @@ -40,124 +40,139 @@ $ npm -v

* **Your Answer:**

---
---Forking and cloning creates a copy of the repository on which changes could be made and a pull request created to merge with original repo. In cloning, a local copy is created in the machine where changes could be added and commited and then pushed to remote repo.

- [ ] Run `npm init -y` from the command line

* **Question:** What does `npm init` do? How does the `-y` flag modify that command?

* **Your Answer:**

---
---npm init command initializes the project and creates repository, bugs and homepage in the package.json file. -y flag takes the default project name and settings and does not ask it.

- [ ] Take a look at the file that was generated by the previous command

* **Question:** What is the purpose of the following keys? "name", "scripts", "license"

* **Your Answer:**

---
---name - contains package name
scripts - dictionary containing script commands that are run at various times in the lifecycle of your package. The key is the lifecycle event, and the value is the command to run at that point. By default, creates an empty test script
license - license of the package so that users know how to use the package

- [ ] Create a `.gitignore` file

* **Question:** What is the purpose of the `.gitignore` file? What is the significance of a "dot-file?"

* **Your Answer:**

---
--- gitignore file specifies intentionally untracked files that Git should ignore. dot-file are files treated as hidden files.

- [ ] Create an `index.js` file with the following contents: `console.log('Hello, Node!')`

* **Question:** From the command line, how can you run this file?

* **Your Answer:**

---
---node index.js

- [ ] Run `npm test` from the command line

* **Question:** What happens and how is this related to what is in the `package.json` file?
* **Question:** What happens and how is this related to what is in the `package.json` file?

* **Your Answer:**

---
---> w1-node-ecosystem@1.0.0 test C:\Rubini\Technical\Personal\UW\JScript400A\w1-node-ecosystem

> echo "Error: no test specified" && exit 1

"Error: no test specified"
npm ERR! Test failed. See above for more details.

test Scripts from package.json are run

- [ ] Create a new "script" command called "start" that has the following value: `node index.js`

* **Question:** What will you enter on the command line to run that script?

* **Your Answer:**

---
---npm start

- [ ] Change the name of your "start" script to "my-file"

* **Question:** The same pattern will not work to try and run this script. How can you successfully get this script to run?

* **Your Answer:**

---
---npm run my-file

- [ ] Create a new file called `profile.js`. Inside the file, copy the following but replace `<your-name>` with your name:

```js
module.exports = '<your-name>'
module.exports = "<your-name>";
```

Add the following to your `index.js` file. Then, run your file.

```js
const profile = require('./profile.js')
console.log(profile)
const profile = require("./profile.js");
console.log(profile);
```

* **Question:** What gets logged? Why?

* **Your Answer:**
Hello, Node!
Rubini
The file profile.js is logged in the console.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be more precise, whatever it is you've exported gets logged. It's not necessarily the entire file. This becomes more important when you have multiple functions in a file.


* **Question:** What is `module.exports` and what is its _type_ in JavaScript? What is `require` and what is its _type_ in JavaScript?
- **Question:** What is `module.exports` and what is its _type_ in JavaScript? What is `require` and what is its _type_ in JavaScript?

* **Your Answer:**
- **Your Answer:**

---
---'module.exports' is the object that's actually returned as the result of a require call - it exposes internally scoped things out of module. Here the type is string.
'require' is used to load to the module which to be exposed. Here, the type is string.

- [ ] We can only export one thing from files when using Node. With that said, export both your name and your birthday from the `profile.js` file.

* **Question:** What are some ways you can solve this problem?

* **Your Answer:**

---
---Wrap them in a collection like object or array and access them. Thus export only one object.

- [ ] Add the following to your `index.js` file. Then, run your file.
```js
const path = require('path')
console.log(path.resolve())
const path = require("path");
console.log(path.resolve());
```

* **Question:** What is `path` and where does it come from?

* **Your Answer:**

---
---node gets the path(the folder we are currently in) from the built in module Path. The path.resolve() method resolves a sequence of paths or path segments into an absolute path.

- [ ] Install the [moment](https://www.npmjs.com/package/moment) package

* **Question:** What command can you run to install this package?

* **Your Answer:**

---
---npm install moment

- [ ] On your own, use this package in the `index.js` file

* **Question:** Do you need to use a `./` to require the package? Why or why not?

* **Your Answer:**

---
---No. It depends on the where the file or folder is placed inside the package.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This question is asking about why you wouldn't do the following:

const moment = require('./moment')

So, in this case you do not do the above because you do not have a file called moment, but a package you've installed.


- [ ] Move your `profile.js` file into a `src/` folder. Update the path in your `index.js` file to ensure everything continues to work.

#### Resources

- [Node.js Built-In Modules](https://nodejs.org/dist/latest-v12.x/docs/api/)
- [NPM: Moment](https://www.npmjs.com/package/moment)
- [NPM: Moment](https://www.npmjs.com/package/moment)