Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1b6ebc6

Browse files
committed
Moved modules to ES5 directory
1 parent fcd6851 commit 1b6ebc6

16 files changed

+275
-0
lines changed

es5/week1/MAKEME.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
> Please help us improve and share your feedback! If you find better tutorials or links, please share them by opening a Pull Request.
2+
3+
# HackYourFuture Node.js - Homework week 1
4+
5+
## Assignment:
6+
Create an http server that can add and subtract from a number, which we will call the "state". Please see in `index.js` in this folder as starting material. Pay extra attention to line 21, which contains some hints for this week `console.log('New http request received', request.url);`
7+
8+
Rule 1: DO NOT USE EXPRESS.JS
9+
Rule 2: you can use other packages, but you HAVE to also make a version WITHOUT any NPM packages (http, of course, is not NPM but a node native package)
10+
```js
11+
// The state
12+
var state = 10;
13+
```
14+
15+
Endpoints criteria
16+
```js
17+
// /state
18+
// response: the current state in a html format
19+
// when the server starts, this should return "10"
20+
http://localhost:8080/state
21+
22+
// /add
23+
// Response: "ok" in html format
24+
// This should add 1 to the current state
25+
http://localhost:8080/add
26+
27+
// /remove
28+
// Response: "ok" in html format
29+
// This should subtract 1 ƒrom the current state
30+
http://localhost:8080/remove
31+
32+
// /reset
33+
// Response: "ok" in html format
34+
// This should set the state back to 10
35+
http://localhost:8080/reset
36+
37+
// Any other URL
38+
// Response: return error code 404: Not found with a friendly message
39+
// and do not change the state variable
40+
http://localhost:8080/subtract
41+
```
42+
43+
## Reading
44+
### Callbacks:
45+
Video: https://www.youtube.com/watch?v=pTbSfCT42_M
46+
Read: http://callbackhell.com/
47+
48+
### Require/exporting
49+
Video: https://www.youtube.com/watch?v=e1Ln1FrLvh8
50+
Read: http://openmymind.net/2012/2/3/Node-Require-and-Exports/
51+
52+
### http, http listen
53+
- Video basic: https://www.youtube.com/watch?v=pYOltVz7kL0
54+
- Video routing: https://www.youtube.com/watch?v=_D2w0voFlEk (please focus on request.url, not request.method)
55+
- Read: [Node JS documentation about http](https://nodejs.org/en/docs/guides/anatomy-of-an-http-transaction/)
56+
- Read Advanced:
57+
58+
refresh on command line
59+
Video Mac/linux:
60+
Video PC: -- ()
61+
62+
While not strictly homework, we’ve created another playlist if you’d like to learn more or review (and as JavaScript developers, you should). https://www.lynda.com/SharedPlaylist/78e6513f51bb4102b03349460491b4e3

es5/week1/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
> Please help us improve and share your feedback! If you find better tutorials or links, please share them by opening a Pull Request.
2+
3+
# HackYourFuture Node.js - Reading material week 1
4+
5+
"What it really means is that Node.js is not a silver-bullet new platform that will dominate the web development world. Instead, it’s a platform that fills a particular need."
6+
7+
### What is Node.js?
8+
> Read: [What is NodeJS? What can you do with it? Why should you use it?](https://medium.com/@paynoattn/what-is-nodejs-what-can-you-do-with-it-why-should-you-use-it-8c8d6df32d6d#.qvbp8g4dq) _estimated time: 10 minutes_
9+
10+
### Getting started with Node.js and npm
11+
> Tutorials: [NPM tutorials. Follow chapters 1 - 10](https://docs.npmjs.com/getting-started/installing-node) _estimated time: 4-6 hours_
12+
13+
### Asynchronous callbacks
14+
Although most of this was already covered by the JavaScript class, let's refresh our memories on Callbacks.
15+
> Read: [Understanding Asynchronous JavaScript Callbacks Through Household Chores
16+
](https://medium.freecodecamp.com/understanding-asynchronous-javascript-callbacks-through-household-chores-e3de9a1dbd04#.8ilr4a7aj) _estimated time: ~1 hour_
17+
18+
### Control flow and events
19+
An important term when making applications is _control flow_. You already know all about it. Read through this page and answer this question: how do we control "flow" in JavaScript?
20+
> Read: [Examples of control flow in JavaScript](https://github.com/ummahusla/Codecademy-Exercise-Answers/tree/master/Language%20Skills/JavaScript/Unit%2005%20Control%20Flow/01%20More%20on%20Control%20Flow%20in%20JS)
21+
22+
### Check out these video's to prep for the second lecture:
23+
>Watch : [Custom made playlist :boom: Lynda.com](https://www.lynda.com/SharedPlaylist/a034fd969ef945bb9ebbd9490cc75d5a)

es5/week1/index.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// To run this file: node index.js
2+
// Then in your browser: http://localhost:8080
3+
var http = require('http');
4+
5+
var port = 8080;
6+
7+
var server = http.createServer();
8+
9+
// Start the HTTP server, start listening for requests
10+
server.listen(port, function(error) {
11+
if (error) {
12+
console.log(error);
13+
} else {
14+
console.log('api listening on port', port);
15+
}
16+
});
17+
18+
// Create a event handler for "request"
19+
// this is an alternative way
20+
server.on('request', function(request, response) {
21+
console.log('New http request received', request.url);
22+
response.setHeader('content-type', 'text/html');
23+
response.write('<html><head></head><body><h1>Hello world</h1></body></html>');
24+
response.end();
25+
});

es5/week1/package.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "week1",
3+
"version": "1.0.0",
4+
"description": "Week 1 homework",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/HackYourFuture/Node.js.git"
12+
},
13+
"keywords": [
14+
"nodejs"
15+
],
16+
"author": "Erol",
17+
"license": "ISC",
18+
"bugs": {
19+
"url": "https://github.com/HackYourFuture/Node.js/issues"
20+
},
21+
"homepage": "https://github.com/HackYourFuture/Node.js#readme"
22+
}

es5/week1/repeated-mistakes.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Some examples of last week
2+
// 1: Do not forget to assign a new number when adding / subtracting
3+
4+
var state = 0;
5+
6+
console.log('original state is', state);
7+
console.log('plus one state is', state + 1);
8+
console.log('plus another one state is', state + 1);
9+
10+
// ---
11+
// 2: Be stylish!
12+
13+
// Watch spaces and tabs:
14+
// Bad: if (request.url==='/' || request.url==='/state' || request.url==='/reset'){
15+
// Good: if (request.url === '/' || request.url === '/state' || request.url === '/reset') {
16+
17+
// ---
18+
// 3: Think and write DRY: Do Not Repeat Yourself
19+

es5/week2/MAKEME.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
> Please help us improve and share your feedback! If you find better tutorials or links, please share them by opening a Pull Request.
2+
3+
# HackYourFuture Node.js - Homework week 2
4+
5+
## Assignment for this week
6+
These are the specs for this week's assignment:
7+
- The user can run a NodeJs to-do app
8+
- The user can be able to run the file using node index.js
9+
- There should be a "help" section that lists all the commands for how to use the app
10+
11+
The following commands should be present:
12+
- No command: show help section (`node index.js`)
13+
- help: show help section (`node index.js help`)
14+
- list: show current todo's, or show an appropriate text if there are no todos (`node index.js list`)
15+
- add: add a todo item. all the words behind "add" are entered as 1 todo item to the list (`node index.js add "Buy groceries"`)
16+
- remove: remove a todo item by its 1-base index. (`node index.js remove 2`)
17+
- reset: remove all todo items from the list (`node index.js reset`)
18+
19+
- *BONUS:* update: update a todo item with new text (`node index.js update 3 "Wash teeth"`)
20+
21+
### Consider this:
22+
- What representation you use in your file (CSV, TSV, JSON, ...)
23+
- Handle edge cases, i.e. control what happens if user enters unexpected input

es5/week2/README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
> Please help us improve and share your feedback! If you find better tutorials or links, please share them by opening a Pull Request.
2+
3+
# HackYourFuture Node.js - Reading material week 2
4+
5+
## Last weeks Summary
6+
Last week we looked at building an HTTP interface. The interface allowed us to get a state, and manipulate the state (add, subtract, reset).
7+
8+
## Today's meal
9+
1. Recap last week
10+
2. Homework
11+
3. Questions & Answers (Q&A)
12+
4. Other topics
13+
4. Persisting data beyond the lifetime of the app.
14+
5. Building a Command Line Interface / Working with arguments
15+
6. Using Node.JS's FileSystem (FS)
16+
7. CRUD operations
17+
8. This week's assignment
18+
19+
## Reading material
20+
21+
### Something about ES6 I want you guys to know
22+
You may hear us talking about this "ES6" all the time. ES6 basically means: the latest version of JavaScript. It has a lot of really nice new features that makes life as developer easier. For you guys, you should remember the following:
23+
> During the NodeJS course, we will teach you some ES6 features, like Fat Arrow. It's *extremely* important to know whether a function comes from ES6 or from an older version of JavaScript. Why? [Because browsers don't support every new feature just yet](http://kangax.github.io/compat-table/es6/). With Node, on the other hand, you can always control which version of Javascript is running, because it's running on your computer, not in the browser. Node Version 6.x that you are running supports most ES6.
24+
So in summary: if you're working on the frontend, you probably don't want to use es6 just yet. In backend, type node --version to see which version you are running, and make sure everyone on the team has the same version by adding "engine" to `package.json` like so:
25+
26+
```js
27+
"dependencies": {
28+
...
29+
},
30+
"devDependencies": {
31+
...
32+
},
33+
"engines": {
34+
"node": ">=6.5.0" // this means you need 6.5 or higher
35+
},
36+
```
37+
38+
### 1. ES6: Fat Arrow functions
39+
This is one example of how ES6 can help us write cleaner code. I'm adding this as first reading material because it's used a lot on the NodeJS documentation website, so it's a good idea to understand what this means. Bonus points if you write your callbacks this way.
40+
[Blogpost Sitepoint]([https://www.sitepoint.com/es6-arrow-functions-new-fat-concise-syntax-javascript/)
41+
[Video]([https://www.youtube.com/watch?v=J85lRtO_yjY)
42+
43+
### 2. NodeJS Process:
44+
Don't have to remember everything in this video, just a nice outline
45+
[Egghead video tutorial](https://egghead.io/lessons/node-js-the-node-js-process-object)
46+
Only read the part about "process.argv"
47+
[Node.JS docs - process.argv](https://nodejs.org/docs/latest/api/process.html#process_process_argv)
48+
49+
### 3. NodeJS FS
50+
Only read the part about readFile, appendFile (you will need this in your assignment)
51+
[Node.JS docs - fs.readFile](https://nodejs.org/api/fs.html#fs_fs_readfile_file_options_callback)
52+
[Node.JS docs - fs.appendFile](https://nodejs.org/api/fs.html#fs_fs_appendfile_file_data_options_callback)
53+
54+
### 4. Node Fundamentals
55+
Read parts:
56+
- 3.1, 3.2
57+
- 4.1, 4.3
58+
[Airpair tutorial](https://www.airpair.com/javascript/node-js-tutorial#3-node-fundamentals)
59+
60+
## As you finish that up, don’t forget to watch next week’s video playlist to prepare for Express.
61+
>You’ll find it here: [Lynda :information_desk_person:](https://www.lynda.com/SharedPlaylist/e8a2fec772bb462da38429629a34f3b7)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

es5/week3/MAKEME.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
> Please help us improve and share your feedback! If you find better tutorials or links, please share them by opening a Pull Request.
2+
3+
# HackYourFuture Node.js - Homework week 3
4+
5+
### Assignment for this weak:
6+
7+
- Fork https://github.com/HackYourFuture/class7-nodejs-week3.git.
8+
- Read through the code, make sure you understand the flow of the program
9+
- Add three more actions
10+
- `clear` (`DELETE /todos`) which will clear the list of todos
11+
- `markAsDone` (`POST /todos/:id/done`) which will set the `done` flag of a single todo to `true`
12+
- `markAsNotDone` (`DELETE /todos/:id/done`) which will set the `done` flag of a single todo to `false`
13+
- Update your README to reflect your new actions!
14+
15+
Take care of the following:
16+
17+
- All requests that need a body should be in JSON, and follow the request structure of the other actions
18+
- All responses should be in JSON, and follow the response structure of the other actions
19+
- Follow the anatomy of the project
20+
- Make your code DRY (see https://en.wikipedia.org/wiki/Don%27t_repeat_yourself)
21+
- Follow the REST design principles: use the proper method, response status codes, and consistent URL paths
22+
- Test your API using Postman

es5/week3/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
> Please help us improve and share your feedback! If you find better tutorials or links, please share them by opening a Pull Request.
2+
3+
# HackYourFuture Node.js - Reading material week 3
4+
5+
### Todays' Meal
6+
7+
1. Recap last Week
8+
2. Homework
9+
3. Q&A
10+
4. Other topics
11+
5. Typescript vs ES6, transpiling javascript
12+
7. Testing with Postman
13+
8. MVC model
14+
9. Express vs native http library
15+
6. Building a REST web API for Todos
16+
17+
## Check out the React repo [here](https://github.com/HackYourFuture/React)
18+
And find out how you can prepare for the first React lecture :dancers:
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)