diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b512c09 --- /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..b69866e --- /dev/null +++ b/index.js @@ -0,0 +1,15 @@ +console.log('Hello, Node!') +const profile = require('./node_modules/moment/src/profile') +console.log(profile) + +const path = require('path') +console.log(path.resolve()) + +const moment = require('./node_modules/moment/moment.js') +/*this also works +const moment = require('moment') +node knows where to look +*/ + +const timenow = moment().format('LTS') +console.log(timenow) \ 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..3a4fe73 --- /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 \"Error: no test specified\" && exit 1", + "my-file": "node index.js" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/toan-myGitHub/w1-node-ecosystem.git" + }, + "keywords": [], + "author": "", + "license": "ISC", + "bugs": { + "url": "https://github.com/toan-myGitHub/w1-node-ecosystem/issues" + }, + "homepage": "https://github.com/toan-myGitHub/w1-node-ecosystem#readme", + "dependencies": { + "moment": "^2.24.0" + }, + "devDependencies": {} +} diff --git a/readme.md b/readme.md index ccca3f4..d55deae 100644 --- a/readme.md +++ b/readme.md @@ -28,7 +28,7 @@ To complete this lesson, make sure that `node` and `npm` is installed and can be $ node -v v12.2.0 -$ npm -v + 6.9.0 ``` @@ -39,8 +39,10 @@ $ npm -v * **Question:** What is the difference between forking and cloning a repository as opposed to just cloning a repository? * **Your Answer:** +just cloning a repository - make no linking back to your github repo, no updaing when things are changed +forking and cloning - linking to your github repo, updates can be pushed to online repo + ---- - [ ] Run `npm init -y` from the command line @@ -48,7 +50,16 @@ $ npm -v * **Your Answer:** ---- +npm init +to initialize a project +promt for input from user +project's name, +project's version, +project's description, + +npm init -y +-y stands for yes +generate an empty npm project without going through an interactive process - [ ] Take a look at the file that was generated by the previous command @@ -56,7 +67,9 @@ $ npm -v * **Your Answer:** ---- +name: project's name +scripts: to automate repetitive tasks, put them in scripts if you dont want to type long line into command promt +license: project's license set to ISC Internet Systems Consortium license - [ ] Create a `.gitignore` file @@ -64,7 +77,14 @@ $ npm -v * **Your Answer:** ---- +.gitignore +contain files that to be ignore: pets.json +not get push/update to GitHub +files that change all the time while testing/building + +dot-file +configuration files +hidden files - [ ] Create an `index.js` file with the following contents: `console.log('Hello, Node!')` @@ -72,7 +92,7 @@ $ npm -v * **Your Answer:** ---- +node index.js - [ ] Run `npm test` from the command line @@ -80,7 +100,9 @@ $ npm -v * **Your Answer:** ---- + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, - [ ] Create a new "script" command called "start" that has the following value: `node index.js` @@ -88,7 +110,10 @@ $ npm -v * **Your Answer:** ---- +npm start +> w1-node-ecosystem@1.0.0 start C:\source\Summer2019\w1-node-ecosystem +> node index.js +Hello, Node! - [ ] Change the name of your "start" script to "my-file" @@ -96,7 +121,8 @@ $ npm -v * **Your Answer:** ---- +my-file is not one of npm command + - [ ] Create a new file called `profile.js`. Inside the file, copy the following but replace `` with your name: ```js @@ -112,12 +138,30 @@ $ npm -v * **Question:** What gets logged? Why? * **Your Answer:** +PS C:\source\Summer2019\w1-node-ecosystem> node index.js +Hello, Node! +Toan Bui + * **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 +exported as a module for future use in other js files + +ex: in hello.js we have +module.exports = 'Hello world'; + +require +to use modules from other js files +ex: in index.js we have +const gretting = require('./hello.js'); +console.log(greeting); +the output is Hello world + +type in JavaScript +String, Number, Boolean, Undefined, Null, Object, Array, 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,7 +169,7 @@ $ npm -v * **Your Answer:** ---- +module.exports = {age, name, phone} - [ ] Add the following to your `index.js` file. Then, run your file. ```js @@ -137,7 +181,10 @@ $ npm -v * **Your Answer:** ---- +Hello, Node! +Toan Bui +C:\source\Summer2019\w1-node-ecosystem + - [ ] Install the [moment](https://www.npmjs.com/package/moment) package @@ -145,7 +192,9 @@ $ npm -v * **Your Answer:** ---- +npm install moment --save +https://momentjs.com/ + - [ ] On your own, use this package in the `index.js` file @@ -153,10 +202,22 @@ $ npm -v * **Your Answer:** ---- +const moment = require('./node_modules/moment/moment.js') +const timenow = moment().format('LTS') +console.log(timenow) + +Hello, Node! +Toan Bui +C:\source\Summer2019\w1-node-ecosystem +7:32:32 PM + + - [ ] Move your `profile.js` file into a `src/` folder. Update the path in your `index.js` file to ensure everything continues to work. +const profile = require('./node_modules/moment/src/profile') +console.log(profile) + #### Resources - [Node.js Built-In Modules](https://nodejs.org/dist/latest-v12.x/docs/api/)