From 2dd1404ed8271bff73791d4efb2e052a49437668 Mon Sep 17 00:00:00 2001 From: Tom Workman Date: Mon, 1 Jul 2019 21:52:56 -0500 Subject: [PATCH] commit assignmenet work --- .gitignore | 1 + index.js | 10 +++++++ package-lock.json | 13 +++++++++ package.json | 25 ++++++++++++++++ readme.md | 72 ++++++++++++++++++++++++++++++++--------------- src/profile.js | 6 ++++ 6 files changed, 105 insertions(+), 22 deletions(-) create mode 100644 .gitignore create mode 100644 index.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..40b878d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules/ \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..e9a0a54 --- /dev/null +++ b/index.js @@ -0,0 +1,10 @@ +// console.log('Hello, Node!') +const profile = require('./src/profile') +console.log(profile) + +// const path = require('path') +// console.log(path.resolve()) + + +const moment = require('moment') +console.log(moment().format('MMMM Do YYYY, h:mm:ss a')) \ No newline at end of file diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..f2886cb --- /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://registry.npmjs.org/moment/-/moment-2.24.0.tgz", + "integrity": "sha512-bV7f+6l2QigeBBZSM/6yTNq4P2fNpSWj/0e7jQcy87A8e7o2nAfP/34/2ky5Vw4B9S446EtIhodAzkFCcR4dQg==" + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..8867836 --- /dev/null +++ b/package.json @@ -0,0 +1,25 @@ +{ + "name": "w1-node-ecosystem", + "version": "1.0.0", + "description": "Welcome to JSCRIPT 400 - Server Side Development with JavaScript", + "main": "index.js", + "scripts": { + "test": "echo \"Hello world, the test is failing!!!\" && exit 1", + "start": "node index.js", + "dev": "node index.js" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/tworkman512/w1-node-ecosystem.git" + }, + "keywords": [], + "author": "", + "license": "ISC", + "bugs": { + "url": "https://github.com/tworkman512/w1-node-ecosystem/issues" + }, + "homepage": "https://github.com/tworkman512/w1-node-ecosystem#readme", + "dependencies": { + "moment": "^2.24.0" + } +} diff --git a/readme.md b/readme.md index ccca3f4..a258a65 100644 --- a/readme.md +++ b/readme.md @@ -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 @@ -39,8 +39,9 @@ $ npm -v * **Question:** What is the difference between forking and cloning a repository as opposed to just cloning a repository? * **Your Answer:** + `git fork` - creates a safe environment for you to write code and create experiments without impacting the master branch. You could merge this code in later. ---- +## `git clone` - creates a copy locally for you to work in and keep track of the master remote repository. - [ ] Run `npm init -y` from the command line @@ -48,7 +49,7 @@ $ npm -v * **Your Answer:** ---- +## It says `yes` to everything when you initiate a new node project and makes assumptions on certain fields about what should be filled out. - [ ] Take a look at the file that was generated by the previous command @@ -56,6 +57,10 @@ $ npm -v * **Your Answer:** +- `name` - Is the name of the project. Important if you plan to publish your package. +- `scripts` - Is where you define any default and/or custom commands that are run at various times of your package lifecycle. +- `license` - Is for if you need to have any special licensing for your project. It let's people know whether or not they are permitted to use it and if you are placing any special restrictions on it's use. + --- - [ ] Create a `.gitignore` file @@ -64,23 +69,24 @@ $ npm -v * **Your Answer:** ---- +Using git as your version control system, you can create a .dot file such as `.gitignore` to tell git which file changes to not keep track of. Having a `.` in front of a file creates a hidden file. Typically want to hide things like `node_modules`, `API key`, etc. - [ ] 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:** + In your terminal, you run `node index.js` ---- +## You would run `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:** ---- +It will display back `npm ERR! Test failed. See above for for more details` in your terminal. You would need to specify any test scripts here and it can print to the terminal any custom messaging you write. - [ ] Create a new "script" command called "start" that has the following value: `node index.js` @@ -88,6 +94,8 @@ $ npm -v * **Your Answer:** +`npm start` - default script + --- - [ ] Change the name of your "start" script to "my-file" @@ -96,47 +104,65 @@ $ npm -v * **Your Answer:** + If you create a custom script, you have to add the `run` keyword before your custom script name. + --- - [ ] Create a new file called `profile.js`. Inside the file, copy the following but replace `` with your name: + ```js - module.exports = '' + module.exports = ""; ``` 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:** -* **Question:** What is `module.exports` and what is its _type_ in JavaScript? What is `require` and what is its _type_ in JavaScript? +It will log out the string with my name because I have exported it and made it available to be used elsewhere in the app. -* **Your Answer:** +- **Question:** What is `module.exports` and what is its _type_ in JavaScript? What is `require` and what is its _type_ in JavaScript? ---- +- **Your Answer:** + +It's an object. You can create an object or an array and then export it. - [ ] 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:** + You could declare a `const` object and export it like the following. This now makes it accessible elsewhere in your project. + +``` +const person = { + name: 'Tom Workman', + age: 1000, +} + +module.exports = person +``` --- - [ ] 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 just a package that comes with Node. It's a module that is part of Node. + --- - [ ] Install the [moment](https://www.npmjs.com/package/moment) package @@ -145,6 +171,8 @@ $ npm -v * **Your Answer:** +Run `npm i moment` + --- - [ ] On your own, use this package in the `index.js` file @@ -153,11 +181,11 @@ $ npm -v * **Your Answer:** ---- +Nope! Node knows to look for it in the `package.json`. - [ ] 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..52c7bff --- /dev/null +++ b/src/profile.js @@ -0,0 +1,6 @@ +const person = { + name: "Tom Workman", + age: 1000 +}; + +module.exports = person;