Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
9 changes: 9 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const profile = require('./src/profile.js')
console.log(profile.age)
console.log(profile.name)

// const path = require('path')
// console.log(path.resolve())

// const moment = require('moment')
// console.log(moment().format('MMMM Do YYYY, h:mm:ss a'))
1 change: 1 addition & 0 deletions moment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
moment().format('MMMM Do YYYY, h:mm:ss a');
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "w1-node-ecosystem",
"version": "1.0.0",
"description": "Welcome to JSCRIPT 400 - Server Side Development with JavaScript",
"main": "index.js",
"scripts": {
"start": "node index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/charlottewest/w1-node-ecosystem.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/charlottewest/w1-node-ecosystem/issues"
},
"homepage": "https://github.com/charlottewest/w1-node-ecosystem#readme",
"dependencies": {
"moment": "^2.24.0"
}
}
63 changes: 36 additions & 27 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,71 +34,78 @@ $ npm -v

### Instructions & Guiding Questions

- [ ] Fork & Clone this repository
- [x] Fork & Clone this repository

* **Question:** What is the difference between forking and cloning a repository as opposed to just cloning a repository?

* **Your Answer:**

Forking is making a copy of a repository. After cloning your forked repo, any commits will be against the copy. Cloning a repository means that any commits will be against the original repo.
---

- [ ] Run `npm init -y` from the command line
- [x] 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` created package.json file and then `-y` automatically filled out the contents (made some good assumptions)
---

- [ ] Take a look at the file that was generated by the previous command
- [x] 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 - name of the app/project, scripts - any scripts used to help run the app, license - it's a license!
---

- [ ] Create a `.gitignore` file
- [x] Create a `.gitignore` file

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

* **Your Answer:**

A file that lists files that you want git to ignore. A dot file is a hidden file.
---

- [ ] Create an `index.js` file with the following contents: `console.log('Hello, Node!')`
- [x] 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
- [x] 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 /Users/charlotte.west/js_cert/js-course-3/w1-node-ecosystem
> echo "Error: no test specified" && exit 1

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

The test script isn't set up in the scripts section of package.json. Whatever string is in the package.json script section will get run. In this case an echo command.
---

- [ ] Create a new "script" command called "start" that has the following value: `node index.js`
- [x] 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"
- [x] 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:
- [x] 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>'
```
Expand All @@ -112,22 +119,24 @@ $ npm -v
* **Question:** What gets logged? Why?

* **Your Answer:**
'charlotte' - because we exported the string from the profile.js file and imported it into our index file. Then when we ran our start command (which runs the index.js file) it does what we asked it to do in profile.js

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

* **Your Answer:**

`module.exports` -
`require` - It's a function that takes a string that is a path to a file.
Copy link
Contributor

Choose a reason for hiding this comment

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

  • module.exports is by default an object. Whatever you assign to it will be what is pulled in when you require() elsewhere.

---

- [ ] 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.
- [x] 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:**

We can export both variables as an array
Copy link
Contributor

Choose a reason for hiding this comment

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

This is true, although more typically we'll export it as an object (i.e. {})

---

- [ ] Add the following to your `index.js` file. Then, run your file.
- [x] Add the following to your `index.js` file. Then, run your file.
```js
const path = require('path')
console.log(path.resolve())
Expand All @@ -136,28 +145,28 @@ $ npm -v
* **Question:** What is `path` and where does it come from?

* **Your Answer:**

Path is a built in node module.
---

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

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

* **Your Answer:**

`npm i 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:**

Not if it's within the node_modules folder. Node will automatically check that folder.
---

- [ ] Move your `profile.js` file into a `src/` folder. Update the path in your `index.js` file to ensure everything continues to work.
- [x] 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)
3 changes: 3 additions & 0 deletions src/profile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const name = 'charlotte west'
const age = 205
module.exports = {name, age}