diff --git a/index.js b/index.js new file mode 100644 index 0000000..cd2f67d --- /dev/null +++ b/index.js @@ -0,0 +1,5 @@ +const profile = require('./profile.js') + console.log(profile) + + const path = require('path') + console.log(path.resolve()) \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..e13ed80 --- /dev/null +++ b/package.json @@ -0,0 +1,13 @@ +{ + "name": "Week-1", + "version": "1.0.0", + "description": "By the end of this lesson, you should be able to read, write, and update files with NodeJS.", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", + "my-file": "node index.js" + }, + "keywords": [], + "author": "", + "license": "ISC" +} diff --git a/profile.js b/profile.js new file mode 100644 index 0000000..7e6eb36 --- /dev/null +++ b/profile.js @@ -0,0 +1 @@ +module.exports = `Beau Barth`; \ No newline at end of file diff --git a/readme.md b/readme.md index ccca3f4..984fc30 100644 --- a/readme.md +++ b/readme.md @@ -1,163 +1,165 @@ -# Setting up a Project with Node - -Welcome to JSCRIPT 400 - Server Side Development with JavaScript - -During class, we will be using repositories like these to develop skills and solidify concepts. I would recommend reading through the instructions _before_ coming to class to prime yourself to the material. - -Part of your homework assignment for each class will be to make a Pull Request against this repository. Your Pull Request should include answers to any questions in this document. - -As we work together on this during class, I would encourage you to make comments next to code we write. Explain what is happening in your own words so that later you have those notes as a reference. - -## Core Learning Objective - -* 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 - -### Prereqs - -To complete this lesson, make sure that `node` and `npm` is installed and can be run from the command line. My versions of each are as follows: - -```bash -$ node -v -v12.2.0 - -$ npm -v -6.9.0 -``` - -### Instructions & Guiding Questions - -- [ ] Fork & Clone this repository - -* **Question:** What is the difference between forking and cloning a repository as opposed to just cloning a repository? - -* **Your Answer:** - ---- - -- [ ] Run `npm init -y` from the command line - -* **Question:** What does `npm init` do? How does the `-y` flag modify that command? - -* **Your Answer:** - ---- - -- [ ] 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:** - ---- - -- [ ] Create a `.gitignore` file - -* **Question:** What is the purpose of the `.gitignore` file? What is the significance of a "dot-file?" - -* **Your Answer:** - ---- - -- [ ] 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:** - ---- - -- [ ] Run `npm test` from the command line - -* **Question:** What happens and how is this related to what is in the `package.json` file? - -* **Your Answer:** - ---- - -- [ ] 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:** - ---- - -- [ ] 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:** - ---- - -- [ ] Create a new file called `profile.js`. Inside the file, copy the following but replace `` with your name: - ```js - module.exports = '' - ``` - - Add the following to your `index.js` file. Then, run your file. - ```js - 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? - -* **Your Answer:** - ---- - -- [ ] 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:** - ---- - -- [ ] Add the following to your `index.js` file. Then, run your file. - ```js - const path = require('path') - console.log(path.resolve()) - ``` - -* **Question:** What is `path` and where does it come from? - -* **Your Answer:** - ---- - -- [ ] Install the [moment](https://www.npmjs.com/package/moment) package - -* **Question:** What command can you run to install this package? - -* **Your Answer:** - ---- - -- [ ] 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:** - ---- - -- [ ] 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/) +# Setting up a Project with Node + +Welcome to JSCRIPT 400 - Server Side Development with JavaScript + +During class, we will be using repositories like these to develop skills and solidify concepts. I would recommend reading through the instructions _before_ coming to class to prime yourself to the material. + +Part of your homework assignment for each class will be to make a Pull Request against this repository. Your Pull Request should include answers to any questions in this document. + +As we work together on this during class, I would encourage you to make comments next to code we write. Explain what is happening in your own words so that later you have those notes as a reference. + +## Core Learning Objective + +* 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 + +### Prereqs + +To complete this lesson, make sure that `node` and `npm` is installed and can be run from the command line. My versions of each are as follows: + +```bash +$ node -v +v12.2.0 + +$ npm -v +6.9.0 +``` + +### Instructions & Guiding Questions + +- [ ] 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 a repository makes a server side copy of that repository that is your copy to manage without impacting the original. Changes can be proposed to the original repository however using pull requests as needed to submit updates to the original repository. A forked repository can also remain in sync via pull from the original repository. Cloning a repository creates a local copy of the repository on your machine. + +- [ ] Run `npm init -y` from the command line + +* **Question:** What does `npm init` do? How does the `-y` flag modify that command? + +* **Your Answer:** + +--- The command `npm init` will create a package.json file in the directory which is defined to identify various details about your project such as the project name, version, description, etc. Appending the `-y` after `npm init` will bypass the prompts in terminal and automatically populate the package.json file using default 'npm init' values. The default values can be managed by using `npm config get ` to identify existing values and `npm config set -g` to new key/value pairs globally. + +- [ ] 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` is the name of the project. `scripts` identifies the various scripts or helpers you've created that can be used with your project. `license` identifies any licenses used by or applicable to your project + +- [ ] Create a `.gitignore` file + +* **Question:** What is the purpose of the `.gitignore` file? What is the significance of a "dot-file?" + +* **Your Answer:** + +--- Dot files are hidden plain text configuration files prefixed with '.'; A `.gitignore` file can be used to identify files or directories to be ignored during push/pull such as config files, api keys, node modules, 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:** + +--- To run the index.js file, use the `node index.js` command in the terminal from the project's directory. + +- [ ] Run `npm test` from the command line + +* **Question:** What happens and how is this related to what is in the `package.json` file? + +* **Your Answer:** + +---An error message is returned. This message is defined in the `test` script defined in `scripts` section of the `package.json` file. + +- [ ] 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:** + +---You would use the command `npm start` in the terminal + +- [ ] 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:** + +---If you are not using a standard npm script, you must use the `npm run