Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Lesson 1 for node.js module from the scotland branch #109

Merged
merged 10 commits into from
Jul 28, 2017

Conversation

alexfdz
Copy link
Collaborator

@alexfdz alexfdz commented Jul 26, 2017

#8 cherry-picked lesson 1 for node.js module from the scotland branch

kabaros and others added 9 commits July 26, 2017 21:48
(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 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.
Copy link
Member

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 ® 😉

Copy link
Collaborator

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.

Copy link
Contributor

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

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();
Copy link
Member

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

Copy link
Collaborator Author

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) {
Copy link
Member

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

Copy link
Contributor

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)

Copy link
Collaborator

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.

Copy link
Contributor

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.

Copy link
Collaborator Author

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?

Copy link
Contributor

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!


> 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- endo
+ end


**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
Copy link
Member

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.
Copy link
Collaborator

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) {
Copy link
Collaborator

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);
Copy link
Collaborator

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


# 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.
Copy link
Collaborator

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.
Copy link
Collaborator

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.

Copy link
Collaborator Author

@alexfdz alexfdz Jul 28, 2017

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`.
Copy link
Collaborator

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?

Copy link
Collaborator Author

@alexfdz alexfdz Jul 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexfdz alexfdz merged commit 75441fa into CodeYourFuture:london Jul 28, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants