From 5278f8dcb48896b47b28d39b9d4f74f479e529f1 Mon Sep 17 00:00:00 2001 From: nick-w-nick <43578531+nick-w-nick@users.noreply.github.com> Date: Tue, 8 Oct 2019 11:36:35 -0400 Subject: [PATCH 1/4] Created Node.js folder + Express.js beginner guide --- Node.js/APIs/Express.js/Beginner/.gitignore | 2 + Node.js/APIs/Express.js/Beginner/README.md | 27 +++++++++++++ Node.js/APIs/Express.js/Beginner/app.js | 38 +++++++++++++++++++ Node.js/APIs/Express.js/Beginner/package.json | 16 ++++++++ 4 files changed, 83 insertions(+) create mode 100644 Node.js/APIs/Express.js/Beginner/.gitignore create mode 100644 Node.js/APIs/Express.js/Beginner/README.md create mode 100644 Node.js/APIs/Express.js/Beginner/app.js create mode 100644 Node.js/APIs/Express.js/Beginner/package.json diff --git a/Node.js/APIs/Express.js/Beginner/.gitignore b/Node.js/APIs/Express.js/Beginner/.gitignore new file mode 100644 index 0000000..25c8fdb --- /dev/null +++ b/Node.js/APIs/Express.js/Beginner/.gitignore @@ -0,0 +1,2 @@ +node_modules +package-lock.json \ No newline at end of file diff --git a/Node.js/APIs/Express.js/Beginner/README.md b/Node.js/APIs/Express.js/Beginner/README.md new file mode 100644 index 0000000..8862499 --- /dev/null +++ b/Node.js/APIs/Express.js/Beginner/README.md @@ -0,0 +1,27 @@ +# Beginner Express.js Server + +This is a quick tutorial for beginners to learn Express.js + +- You will need to have [Node.js](https://nodejs.org/en/) installed prior to starting this tutorial. + _(If this is your first time downloading Node.js, restart your PC after install, or else NPM commands will not work.)_ + +- I recommend downloading the [Postman](https://www.getpostman.com/) client in order to test your endpoints. + +## How to start the server +Using your terminal either via your OS or VS Code, run the two commands below, in this order: +1. **npm install** +2. **npm start** + +Once you've completed the setup, you should see the following in the console after running the above commands: +``` +[nodemon] 1.19.3 +[nodemon] to restart at any time, enter `rs` +[nodemon] watching dir(s): *.* +[nodemon] watching extensions: js,mjs,json +[nodemon] starting `node app.js` +Server started successfully! +[nodemon] restarting due to changes... +[nodemon] starting `node app.js` +Server started successfully! +``` + diff --git a/Node.js/APIs/Express.js/Beginner/app.js b/Node.js/APIs/Express.js/Beginner/app.js new file mode 100644 index 0000000..0142cda --- /dev/null +++ b/Node.js/APIs/Express.js/Beginner/app.js @@ -0,0 +1,38 @@ +const express = require('express'); +const app = express(); + +app.listen(3000, () => console.log('Server started successfully!')); +app.use(express.json()); + +// cd into the Node.js\APIs\Express.js\Beginner folder, and run 'npm install', then 'npm start' to start the server! + +// Simple GET endpoint +app.get('/users', (req, res) => { + const userList = [ + {name: 'Mike', age: 23}, + {name: 'Jim', age: 41}, + {name: 'Terra', age: 19}, + {name: 'Richard', age: 32}, + {name: 'Alex', age: 56}, + ]; + + res.send(userList); + // GET localhost:3000/users = [{"name": "Mike", "age": 23}, {"name": "Jim", "age": 41},..] +}); + +// Simple POST endpoint +app.post('/createUser', (req, res) => { + const userList = [ + {name: 'Mike', age: 23}, + {name: 'Jim', age: 41}, + {name: 'Terra', age: 19}, + {name: 'Richard', age: 32}, + {name: 'Alex', age: 56}, + ]; + + userList.push({name: req.body.name, age: req.body.age}) + + res.send(userList) + // POST localhost:3000/createUser using {"name": "Bob", "age": 44} to add him to the list! +}); + diff --git a/Node.js/APIs/Express.js/Beginner/package.json b/Node.js/APIs/Express.js/Beginner/package.json new file mode 100644 index 0000000..10f4f43 --- /dev/null +++ b/Node.js/APIs/Express.js/Beginner/package.json @@ -0,0 +1,16 @@ +{ + "name": "Beginner", + "version": "1.0.0", + "description": "", + "main": "app.js", + "scripts": { + "start": "nodemon app.js" + }, + "keywords": [], + "author": "", + "license": "ISC", + "dependencies": { + "express": "^4.17.1", + "nodemon": "^1.19.3" + } +} From 0bc8ef91d5d833f8c0436643e4bd73fc952b4d9a Mon Sep 17 00:00:00 2001 From: nick-w-nick Date: Tue, 8 Oct 2019 11:39:44 -0400 Subject: [PATCH 2/4] misc formatting --- Node.js/APIs/Express.js/Beginner/README.md | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Node.js/APIs/Express.js/Beginner/README.md b/Node.js/APIs/Express.js/Beginner/README.md index 8862499..ac87c08 100644 --- a/Node.js/APIs/Express.js/Beginner/README.md +++ b/Node.js/APIs/Express.js/Beginner/README.md @@ -3,7 +3,7 @@ This is a quick tutorial for beginners to learn Express.js - You will need to have [Node.js](https://nodejs.org/en/) installed prior to starting this tutorial. - _(If this is your first time downloading Node.js, restart your PC after install, or else NPM commands will not work.)_ +_(If this is your first time downloading Node.js, restart your PC after install, or else NPM commands will not work.)_ - I recommend downloading the [Postman](https://www.getpostman.com/) client in order to test your endpoints. @@ -20,8 +20,4 @@ Once you've completed the setup, you should see the following in the console aft [nodemon] watching extensions: js,mjs,json [nodemon] starting `node app.js` Server started successfully! -[nodemon] restarting due to changes... -[nodemon] starting `node app.js` -Server started successfully! ``` - From 8b09793e420a92e10234a797525be61887352d47 Mon Sep 17 00:00:00 2001 From: nick-w-nick <43578531+nick-w-nick@users.noreply.github.com> Date: Tue, 8 Oct 2019 11:45:45 -0400 Subject: [PATCH 3/4] reorganizing JS folder --- .../Express.js/Beginner API}/.gitignore | 0 .../Node.js/Express.js/Beginner API/README.md | 27 +++++++++++++++++++ .../Node.js/Express.js/Beginner API}/app.js | 0 .../Express.js/Beginner API}/package.json | 0 4 files changed, 27 insertions(+) rename {Node.js/APIs/Express.js/Beginner => JavaScript/Node.js/Express.js/Beginner API}/.gitignore (100%) create mode 100644 JavaScript/Node.js/Express.js/Beginner API/README.md rename {Node.js/APIs/Express.js/Beginner => JavaScript/Node.js/Express.js/Beginner API}/app.js (100%) rename {Node.js/APIs/Express.js/Beginner => JavaScript/Node.js/Express.js/Beginner API}/package.json (100%) diff --git a/Node.js/APIs/Express.js/Beginner/.gitignore b/JavaScript/Node.js/Express.js/Beginner API/.gitignore similarity index 100% rename from Node.js/APIs/Express.js/Beginner/.gitignore rename to JavaScript/Node.js/Express.js/Beginner API/.gitignore diff --git a/JavaScript/Node.js/Express.js/Beginner API/README.md b/JavaScript/Node.js/Express.js/Beginner API/README.md new file mode 100644 index 0000000..8862499 --- /dev/null +++ b/JavaScript/Node.js/Express.js/Beginner API/README.md @@ -0,0 +1,27 @@ +# Beginner Express.js Server + +This is a quick tutorial for beginners to learn Express.js + +- You will need to have [Node.js](https://nodejs.org/en/) installed prior to starting this tutorial. + _(If this is your first time downloading Node.js, restart your PC after install, or else NPM commands will not work.)_ + +- I recommend downloading the [Postman](https://www.getpostman.com/) client in order to test your endpoints. + +## How to start the server +Using your terminal either via your OS or VS Code, run the two commands below, in this order: +1. **npm install** +2. **npm start** + +Once you've completed the setup, you should see the following in the console after running the above commands: +``` +[nodemon] 1.19.3 +[nodemon] to restart at any time, enter `rs` +[nodemon] watching dir(s): *.* +[nodemon] watching extensions: js,mjs,json +[nodemon] starting `node app.js` +Server started successfully! +[nodemon] restarting due to changes... +[nodemon] starting `node app.js` +Server started successfully! +``` + diff --git a/Node.js/APIs/Express.js/Beginner/app.js b/JavaScript/Node.js/Express.js/Beginner API/app.js similarity index 100% rename from Node.js/APIs/Express.js/Beginner/app.js rename to JavaScript/Node.js/Express.js/Beginner API/app.js diff --git a/Node.js/APIs/Express.js/Beginner/package.json b/JavaScript/Node.js/Express.js/Beginner API/package.json similarity index 100% rename from Node.js/APIs/Express.js/Beginner/package.json rename to JavaScript/Node.js/Express.js/Beginner API/package.json From 8210217846ab67d3a0deafd9c39476491b6770ee Mon Sep 17 00:00:00 2001 From: nick-w-nick <43578531+nick-w-nick@users.noreply.github.com> Date: Tue, 8 Oct 2019 11:47:02 -0400 Subject: [PATCH 4/4] fixing readme --- .../Node.js/Express.js/Beginner API/README.md | 8 ++----- Node.js/APIs/Express.js/Beginner/README.md | 23 ------------------- 2 files changed, 2 insertions(+), 29 deletions(-) delete mode 100644 Node.js/APIs/Express.js/Beginner/README.md diff --git a/JavaScript/Node.js/Express.js/Beginner API/README.md b/JavaScript/Node.js/Express.js/Beginner API/README.md index 8862499..a4da559 100644 --- a/JavaScript/Node.js/Express.js/Beginner API/README.md +++ b/JavaScript/Node.js/Express.js/Beginner API/README.md @@ -3,7 +3,7 @@ This is a quick tutorial for beginners to learn Express.js - You will need to have [Node.js](https://nodejs.org/en/) installed prior to starting this tutorial. - _(If this is your first time downloading Node.js, restart your PC after install, or else NPM commands will not work.)_ +_(If this is your first time downloading Node.js, restart your PC after install, or else NPM commands will not work.)_ - I recommend downloading the [Postman](https://www.getpostman.com/) client in order to test your endpoints. @@ -20,8 +20,4 @@ Once you've completed the setup, you should see the following in the console aft [nodemon] watching extensions: js,mjs,json [nodemon] starting `node app.js` Server started successfully! -[nodemon] restarting due to changes... -[nodemon] starting `node app.js` -Server started successfully! -``` - +``` \ No newline at end of file diff --git a/Node.js/APIs/Express.js/Beginner/README.md b/Node.js/APIs/Express.js/Beginner/README.md deleted file mode 100644 index ac87c08..0000000 --- a/Node.js/APIs/Express.js/Beginner/README.md +++ /dev/null @@ -1,23 +0,0 @@ -# Beginner Express.js Server - -This is a quick tutorial for beginners to learn Express.js - -- You will need to have [Node.js](https://nodejs.org/en/) installed prior to starting this tutorial. -_(If this is your first time downloading Node.js, restart your PC after install, or else NPM commands will not work.)_ - -- I recommend downloading the [Postman](https://www.getpostman.com/) client in order to test your endpoints. - -## How to start the server -Using your terminal either via your OS or VS Code, run the two commands below, in this order: -1. **npm install** -2. **npm start** - -Once you've completed the setup, you should see the following in the console after running the above commands: -``` -[nodemon] 1.19.3 -[nodemon] to restart at any time, enter `rs` -[nodemon] watching dir(s): *.* -[nodemon] watching extensions: js,mjs,json -[nodemon] starting `node app.js` -Server started successfully! -```