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..e891416 100644 --- a/readme.md +++ b/readme.md @@ -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 `` 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 = '' ``` @@ -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. --- -- [ ] 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 --- -- [ ] 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()) @@ -136,15 +145,15 @@ $ 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 @@ -152,12 +161,12 @@ $ 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. +- [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) \ 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}