diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7dbb872 --- /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..80d3e44 --- /dev/null +++ b/index.js @@ -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")); 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..4f589c4 --- /dev/null +++ b/package.json @@ -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" +} diff --git a/readme.md b/readme.md index ccca3f4..63f6b19 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 @@ -40,7 +40,7 @@ $ npm -v * **Your Answer:** ---- +_forking is just a request for cloning_ - [ ] Run `npm init -y` from the command line @@ -48,15 +48,16 @@ $ npm -v * **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 @@ -64,7 +65,8 @@ $ npm -v * **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_ - [ ] Create an `index.js` file with the following contents: `console.log('Hello, Node!')` @@ -72,15 +74,15 @@ $ npm -v * **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"_ - [ ] Create a new "script" command called "start" that has the following value: `node index.js` @@ -88,7 +90,7 @@ $ npm -v * **Your Answer:** ---- +_Start node index.js_ - [ ] Change the name of your "start" script to "my-file" @@ -96,28 +98,31 @@ $ npm -v * **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 `` 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:** + _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. @@ -125,19 +130,19 @@ $ npm -v * **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 @@ -145,7 +150,7 @@ $ npm -v * **Your Answer:** ---- +_npm install moment_ - [ ] On your own, use this package in the `index.js` file @@ -153,11 +158,11 @@ $ npm -v * **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) \ 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..9d5780c --- /dev/null +++ b/src/profile.js @@ -0,0 +1,2 @@ +module.exports = "Shahab"; +//Add the following to your index.js file. Then, run your file.