-
-
Notifications
You must be signed in to change notification settings - Fork 113
Lesson 1 for node.js module from the scotland branch #109
Conversation
(cherry picked from commit 35d9642)
(cherry picked from commit 2a5b2b1)
based on Node Girls workshop (cherry picked from commit 3f53734)
* Move server section up * Add "what is node" section * Add what to use Node for * Add link to package.json for Passport * Add simple server section * Add http section * Add http diagram * Update http section with image * Add tutsplus http tutorial * Add requested changes Changes implemented: - var to const - remove one route example - add routing exercise * Update lesson1.md (cherry picked from commit 6e8e234)
(cherry picked from commit 9b84e7c)
(cherry picked from commit 7d91096)
* Correct typo * Add JSON section * Add app.get link to docs * Add res.send() link to docs * Add url image * Add URL section (cherry picked from commit fe6dc40)
(cherry picked from commit dee8c9f)
(cherry picked from commit 803839f)
### Homework | ||
# What is Node.js? | ||
|
||
> [Node.js®](https://nodejs.org/en/) is a **JavaScript runtime** built on Chrome's **V8 JavaScript engine**. Node.js uses an **event-driven**, **non-blocking** I/O model that makes it lightweight and efficient. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And in plain english? Might be quite nice to explain "runtime", "event-driven" and "non-blocking"?
Also probably no need for the ® 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be awkward to drop those terms without a full explanation of each. If you want to explain what Node is without them you could write something like this...
Your Chrome browser contains a JavaScript runtime (or engine) called V8 and a Web API for performing asynchronous operations such as XHR or setTimeout
. Node is a copy of that engine but with it's own Web API for performing IO operations.
...it may be worth then introducing what is meant by a single-threaded non-blocking IO as part of a conversation about how a JavaScript runtime is built. It is a really important concept that underpins how the language works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The exercise here was to get them used to reading specs and docs. After reading the sentence we went word by word and explained in plain English. So it wasnt that scary after all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@leggsimon @peterthompson do you agree with @Michael-Antczak?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have created #112 to deal with this conversation. @peterthompson I don't know why I cannot assign it to you.
// set response content | ||
res.write('<html><body><h1>This is home Page.</h1></body></html>'); | ||
res.write('<h2>The time is: ' + Date() + '</h2>'); | ||
res.end(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some indentation issues in this block
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in the node-workshop repository
```javascript | ||
const http = require('http'); | ||
|
||
const server = http.createServer(function (req, res) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't feel massively strongly about this but if we're doing ES6, maybe we should use arrow functions? Happy to not though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup .. we asked them to use arrow functions when they try the code and do exercises, but we left optional as few are still not comfortable with it (although I think the London has spent more time with ES6 than here)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd push to drop in ES6 syntax, it's going to serve them best getting work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The other point is that this way it was easier to explain passing a function as an argument using a similar syntax to what they know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@peterthompson I'm moving the code examples to a different repo so should be easier to them to clone, check the code and execute it.
https://github.com/CodeYourFuture/node-workshop
Could you push there your changes in the syntax?
@kabaros from you experience with the module in Scotland, do you think that is a good idea to move the examples to the repo?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we haven't tried that before @alexfdz but it seems like something reasonable to do in this case, maybe just prepare some small changes that they do to the code. I would give this approach a try!
node-db/lesson1.md
Outdated
|
||
> The wizard asks you for the following information: `name`, `version`, `description`, `main`, `test`, `repository`, `keywords`, `author`, `license` - do you understand all of them? | ||
|
||
At the endo of the wizard, you should see a new file called `package.json` in your project's folder. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- endo
+ end
node-db/lesson1.md
Outdated
|
||
**Important:** When you get stuck during the homework you should follow the following "escalation policy". | ||
* First, search for answers on Google and Stack Overflow. If you have an error message, copy and paste it into Google. | ||
* When you are stuck for longer than 20 minutes - no longer! - write a question to your fellow students in the #class1 channel on slack. Take a while to think carefully about the question. This is an important skill. There is a great guide to writing good questions here: http://stackoverflow.com/help/how-to-ask | ||
* When you are stuck for longer than 20 minutes - no longer! - write a question to your fellow students in the #scotland-class1 channel on slack. Take a while to think carefully about the question. This is an important skill. There is a great guide to writing good questions here: http://stackoverflow.com/help/how-to-ask |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#scotland-class1
? or #london-class1
### Homework | ||
# What is Node.js? | ||
|
||
> [Node.js®](https://nodejs.org/en/) is a **JavaScript runtime** built on Chrome's **V8 JavaScript engine**. Node.js uses an **event-driven**, **non-blocking** I/O model that makes it lightweight and efficient. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be awkward to drop those terms without a full explanation of each. If you want to explain what Node is without them you could write something like this...
Your Chrome browser contains a JavaScript runtime (or engine) called V8 and a Web API for performing asynchronous operations such as XHR or setTimeout
. Node is a copy of that engine but with it's own Web API for performing IO operations.
...it may be worth then introducing what is meant by a single-threaded non-blocking IO as part of a conversation about how a JavaScript runtime is built. It is a really important concept that underpins how the language works.
```javascript | ||
const http = require('http'); | ||
|
||
const server = http.createServer(function (req, res) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd push to drop in ES6 syntax, it's going to serve them best getting work.
res.end("Hello World!") | ||
}); | ||
|
||
server.listen(5000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd stick the console log as a callback to the listen function...
server.listen(5000, () => {
console.log('Node.js web server at port 5000 is running...');
});
Otherwise on error it will still say that the server is listening to stdout.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
node-db/lesson1.md
Outdated
|
||
# What is JSON? | ||
|
||
JSON is a type of file for structuring data in a readable way. It is also a really popular format for sending data across the web. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd mention what the acronym stands for, JavaScript Object Notation.
Also I'd add...
-a readable way
+a human-readable way
|
||
Before we write any code, you'll need to install the Express library. We're going to use the **[Node Package Manager (npm)](https://www.npmjs.com/)** to download it using the **`npm install`** command. | ||
|
||
NPM is the place to go to download other Node code written by other people. There are thousands of open-source, 3rd-party Node modules (also known as "packages") by other people that you can download and use in your own projects. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd make a very clear distinction between a registry and a client. npmjs.org is the registry where packages can be found. npm
is a client for downloading and managing those packages. You could go on to mention yarn
is another example of an npm client that you may encounter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The content is now in the london branch, feel free to add a bit of magic to this description
const express = require('express'); | ||
``` | ||
|
||
> We will try and get used to ES6 syntax - so use `const` and `let` instead of `var`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Worth a discussion on what const
and let
are with regard to scope?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you push it to https://github.com/CodeYourFuture/node-workshop?
#8 cherry-picked lesson 1 for node.js module from the scotland branch