-
Notifications
You must be signed in to change notification settings - Fork 31
Shahab node-ecosystem assignment #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
7c820e2
1fe0e66
7170e83
8a38727
f413005
55dcafd
778158b
b8a20a0
631fd78
d59f7bc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| node-modules/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| //const profile = require("./src/profile.js"); | ||
| //console.log(profile); | ||
|
|
||
| // console.log("Hello, Node!"); | ||
|
|
||
| // const path = require("path"); | ||
| // console.log(path.resolve()); | ||
|
|
||
| const moment = require("moment"); | ||
| console.log(moment().format("MMMM Do YYYY, h:mm:ss a")); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| { | ||
| "name": "w1-node-ecosystem", | ||
| "version": "1.0.0", | ||
| "description": "Welcome to JSCRIPT 400 - Server Side Development with JavaScript", | ||
| "main": "index.js", | ||
| "dependencies": { | ||
| "moment": "^2.24.0" | ||
| }, | ||
| "devDependencies": {}, | ||
| "scripts": { | ||
| "test": "echo \"Error: no test specified\" && exit 1", | ||
| "my-file": "node index.js", | ||
| "start": "node index.js" | ||
| }, | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git+https://github.com/Shahab13/w1-node-ecosystem.git" | ||
| }, | ||
| "keywords": [], | ||
| "author": "", | ||
| "license": "ISC", | ||
| "bugs": { | ||
| "url": "https://github.com/Shahab13/w1-node-ecosystem/issues" | ||
| }, | ||
| "homepage": "https://github.com/Shahab13/w1-node-ecosystem#readme" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
||
|
|
@@ -40,124 +40,129 @@ $ npm -v | |
|
|
||
| * **Your Answer:** | ||
|
|
||
| --- | ||
| _forking is just a request for cloning_ | ||
|
|
||
| - [ ] Run `npm init -y` from the command line | ||
|
|
||
| * **Question:** What does `npm init` do? How does the `-y` flag modify that command? | ||
|
|
||
| * **Your Answer:** | ||
|
|
||
| --- | ||
| _creating package.json and -y saying yes to everything_ | ||
|
|
||
| - [ ] 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:** | ||
|
|
||
| --- | ||
| _scripts: scripts are written as usual JSON key-value pairs where the key is the name of the script and the value contains the script you want to execute._ | ||
| _names: It's just the name of the project._ | ||
| _Licenses: you'll need to license it so that others are free to use, change, and distribute the software._ | ||
|
|
||
| - [ ] Create a `.gitignore` file | ||
|
|
||
| * **Question:** What is the purpose of the `.gitignore` file? What is the significance of a "dot-file?" | ||
|
|
||
| * **Your Answer:** | ||
|
|
||
| --- | ||
| _file that we don't want to keep trak of them in the reposetori_ | ||
| _It works anywhere, but its primary use is to hide configuration files in the home directory_ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A "dot-file" is typically a hidden file of some sort. |
||
|
|
||
| - [ ] 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:** | ||
|
|
||
| --- | ||
| _result is "Error: no test specified"_ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct, but the question is about why that is. This is due to the fact that the value for "test" is a command that will print some text to the terminal and then exit. |
||
|
|
||
| - [ ] 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:** | ||
|
|
||
| --- | ||
| _Start node index.js_ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You would type: |
||
|
|
||
| - [ ] 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 my-file will not work since it's not standard npm command to make it work we need to add " run " key word_ | ||
|
|
||
| - [ ] 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:** | ||
| _My name was logged because we just connected different files using "export" and "require" keywords_ | ||
|
|
||
| * **Question:** What is `module.exports` and what is its _type_ in JavaScript? What is `require` and what is its _type_ in JavaScript? | ||
|
|
||
| * **Your Answer:** | ||
|
|
||
| --- | ||
| _The type of module.export is an object and "require" is function_ | ||
|
|
||
| - [ ] 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 use an array or an object and then export the whole 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:** | ||
|
|
||
| --- | ||
| _path is a module that comes with node.js when you install it_ | ||
|
|
||
| - [ ] 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, because we don't have moment file and we pull it from package_ | ||
|
|
||
| - [ ] 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) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| module.exports = "Shahab"; | ||
| //Add the following to your index.js file. Then, run your file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit more than that. I would review the lesson video from yesterday. I explain this more in depth at the beginning of class.