From ab3bf0c0f6eef8e0bee039dc15ba605694fd4c59 Mon Sep 17 00:00:00 2001 From: Charlotte West Date: Sun, 30 Jun 2019 15:32:07 -0700 Subject: [PATCH 1/2] add files for wk 1 assisgnment --- .gitignore | 1 + index.js | 9 +++++++++ moment.js | 1 + package-lock.json | 13 +++++++++++++ package.json | 24 ++++++++++++++++++++++++ readme.md | 37 +++++++++++++++++++++++-------------- src/profile.js | 3 +++ 7 files changed, 74 insertions(+), 14 deletions(-) create mode 100644 .gitignore create mode 100644 index.js create mode 100644 moment.js create mode 100644 package-lock.json create mode 100644 package.json create mode 100644 src/profile.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/index.js b/index.js new file mode 100644 index 0000000..e7c8eaa --- /dev/null +++ b/index.js @@ -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')) diff --git a/moment.js b/moment.js new file mode 100644 index 0000000..db349e3 --- /dev/null +++ b/moment.js @@ -0,0 +1 @@ +moment().format('MMMM Do YYYY, h:mm:ss a'); diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..f97177c --- /dev/null +++ b/package-lock.json @@ -0,0 +1,13 @@ +{ + "name": "w1-node-ecosystem", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "moment": { + "version": "2.24.0", + "resolved": "https://repo.socrata.com:443/artifactory/api/npm/npm-virtual/moment/-/moment-2.24.0.tgz", + "integrity": "sha1-DQVdU/UFKqZTyfbraLtdEr9cK1s=" + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..0b673b3 --- /dev/null +++ b/package.json @@ -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" + } +} diff --git a/readme.md b/readme.md index ccca3f4..01f1b6d 100644 --- a/readme.md +++ b/readme.md @@ -39,7 +39,7 @@ $ npm -v * **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 @@ -47,7 +47,7 @@ $ npm -v * **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 @@ -55,7 +55,7 @@ $ npm -v * **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 @@ -63,7 +63,7 @@ $ npm -v * **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!')` @@ -71,15 +71,22 @@ $ npm -v * **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 /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` @@ -87,7 +94,7 @@ $ npm -v * **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" @@ -95,7 +102,7 @@ $ npm -v * **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 `` with your name: @@ -112,11 +119,13 @@ $ 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. --- - [ ] 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. @@ -124,7 +133,7 @@ $ npm -v * **Question:** What are some ways you can solve this problem? * **Your Answer:** - +We can export both variables as an array --- - [ ] Add the following to your `index.js` file. Then, run your file. @@ -136,7 +145,7 @@ $ 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 @@ -144,7 +153,7 @@ $ npm -v * **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 @@ -152,7 +161,7 @@ $ npm -v * **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. @@ -160,4 +169,4 @@ $ npm -v #### Resources - [Node.js Built-In Modules](https://nodejs.org/dist/latest-v12.x/docs/api/) -- [NPM: Moment](https://www.npmjs.com/package/moment) \ No newline at end of file +- [NPM: Moment](https://www.npmjs.com/package/moment) diff --git a/src/profile.js b/src/profile.js new file mode 100644 index 0000000..12f390f --- /dev/null +++ b/src/profile.js @@ -0,0 +1,3 @@ +const name = 'charlotte west' +const age = 205 +module.exports = {name, age} From 4c5a1dd859fa2f038e7495b72f5075a0c5b5ed5d Mon Sep 17 00:00:00 2001 From: charlottewest Date: Sun, 30 Jun 2019 15:52:17 -0700 Subject: [PATCH 2/2] check the check boxes --- readme.md | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/readme.md b/readme.md index 01f1b6d..e891416 100644 --- a/readme.md +++ b/readme.md @@ -34,7 +34,7 @@ $ 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? @@ -42,7 +42,7 @@ $ npm -v 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? @@ -50,7 +50,7 @@ Forking is making a copy of a repository. After cloning your forked repo, any co `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" @@ -58,7 +58,7 @@ Forking is making a copy of a repository. After cloning your forked repo, any co 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?" @@ -66,7 +66,7 @@ name - name of the app/project, scripts - any scripts used to help run the app, 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? @@ -74,7 +74,7 @@ A file that lists files that you want git to ignore. A dot file is a hidden file `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? @@ -89,7 +89,7 @@ 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? @@ -97,7 +97,7 @@ The test script isn't set up in the scripts section of package.json. Whatever st `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? @@ -105,7 +105,7 @@ The test script isn't set up in the scripts section of package.json. Whatever st `npm run my-file` --- -- [ ] Create a new file called `profile.js`. Inside the file, copy the following but replace `` with your name: +- [x] Create a new file called `profile.js`. Inside the file, copy the following but replace `` with your name: ```js module.exports = '' ``` @@ -128,7 +128,7 @@ The test script isn't set up in the scripts section of package.json. Whatever st `require` - It's a function that takes a string that is a path to a file. --- -- [ ] 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? @@ -136,7 +136,7 @@ The test script isn't set up in the scripts section of package.json. Whatever st We can export both variables as an array --- -- [ ] 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()) @@ -148,7 +148,7 @@ We can export both variables as an array 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? @@ -164,7 +164,7 @@ Path is a built in node module. 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