Today I will tell you about one very interesting community called NodeSchool. This community promotes training on the node.js platform.
A little bit about Node.js:
')
Node or Node.js is a software platform based on the V8 engine (translating JavaScript into machine code) that turns JavaScript from a highly specialized language into a general-purpose language. Node.js adds the ability of JavaScript to interact with I / O devices through its API (written in C ++), to connect other external libraries written in different languages, providing calls to them from JavaScript code. Node.js is used mainly on the server, acting as a web server, but it is possible to develop desktop applications on Node.js (using node-webkit and AppJS for Linux, Windows and MacOS) and even program microcontrollers (for example, tessel and espruino).
Source: en.wikipedia.org
NodeSchool conducts workshops on familiarization with the node.js platform and conducting lessons on the
learnyounode repository. This is a fairly well-known community, the user
ilusha_sergeevich in one of his digests on the topic "Several interesting and useful for the web developer" already mentioned learnyounode by reference. They hold seminars around the world, and if you or your organization expressed a desire to hold your seminar on behalf of this school, you only need to apply on the
website . Last month, the community held workshops in Budapest, London, Norwich, and in the first of this month in our city.
I happened to attend the nodeschool workshop, organized by the New Leaf Initiative. They rented a spacious hall in our city and provided free food. On behalf of the nodeschool, a mentor from the New Leaf Initiative conducted an introductory course on the platform and helped with the lessons. The contingent who came to this seminar was unusual. The 30+ men came, who are most likely programmers, with their families, most of all I remember a pregnant woman with a daughter of 8-9 years who really tried to program :). It was remarkable that there were quite a few students at this seminar.
Attention!From here, dear habrazhiteli, please do not throw stones. For someone it will seem that the information provided below is too easy and useless. But for those who have never tried to program in javaScript or Node.js, it will be quite interesting.
How does this system work?
Let's try using the example of working with Unix-based systems.
First, install Node.js at
http://nodejs.org/Then you install the learnyounode repository:
npm install -g learnyounode
When entering the learnyounode command:

Let's try to go through one lesson?
I think the first “Hello World” is too simple.
Then let's start with the example of the second lesson “Baby Steps”:

Task: Get the sum of the numbers entered.
Before deciding:
We have to create our program.js file (Just use a regular notepad and change the extension to .js)
(Please take into account the fact that the file name can be any, it is not necessary to name the file program.js)To understand the work, let's write there
console.log(process.argv);
PS console.log () is the output statement for node.js
Now run our file from the command line:
node program.js
Our conclusion should be:
[ 'node', '%path%/program.js' ]
This makes us realize that our process.argv is just an array of elements entered on the command line, i.e. if we introduce
node program.js my name is Dan
That our array consists of:
process.argv [0] = node
process.argv [1] =% path% / program.js
process.argv [2] = my
process.argv [3] = name
...
and so on.
We now turn to solving the problem.
Decision:
Let's calculate the sum of three numbers 1,2,3.
When typing in the command line: "
node program.js 1 2 3
", as you already understood, the numbers start with the 3rd element (2nd id) of the array.
Open our program.js and create a variable sum, where we will store our amount.
Then we write a simple for loop, where the condition for exit is our last cell in the array.
In our cycle, we add each cell of our array to the variable sum.
PS How to know the size of our array? Easily, the process.argv.length function returns the size of our array.
Attention : By default, each element of the array is a String (values ​​of the string type.), So we need to change the type of the element from String to Int. How do we do it? Using the Number () function.
Example: Number (process.argv [2]), it turns String "1" into Int 1.
And display our amount by calling console.log (sum)
What it looks like:
var sum = 0; for(var i = 2; i<process.argv.length; i++ ) { sum = sum + Number(process.argv[i]); } console.log(sum);
Save the file and run our program:
node program.js 1 2 3
The conclusion should be simple: 6.
To complete the lesson and test the program, we enter: learnyounode verify node.js
Here is what you should get:

Pretty comfortable, isn't it? The most interesting thing about checking a program is that if our program has errors, we can understand the problem in the columns provided: Actual and Expected. As you probably already understood, the program displays your result under the Actual column, and the expected result under the Expected column. And it gives you a hint in your mistakes.
I hope my article was useful for you, and introduced the basics of node.js.
PS Please take into account that I am a student could be wrong in the terminology in Russian, because He studied programming in English. If you have found a mistake or a distortion of the truth in my stupid language, please write me in PM, and I will definitely correct everything.