All language subtitles for 4. Installing Node.js and Creating our First App 4

af Afrikaans
ak Akan
sq Albanian
am Amharic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranรฎ)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

So we want to use nodejs

and the first important step is that we install it and for that you have to visit

nodejs.org.

There you'll find an installer,

in my case here it picked the right one for my operating system, MacOS but you will also find a version for

Windows

if you're visiting this page on Windows or you manually choose a different version and you can of course

follow along no matter which operating system you're using,

the code you write and the steps you need to take to install nodejs are exactly the same.

You simply download the latest version here, 10.9 in my case and you then simply save it anywhere and run the installer

this gives you. Now simply follow through all the steps which are mentioned in the installer, accept the

license agreement and so on

so simply click through that,

install it on your machine

and once it is completed, you already got everything you will need to write

nodejs

code.

So this is super fast, it's done here,

you can close this now

and now, how do we use nodejs?

Well the easiest way of using it is to open up your local terminal or on windows, powershell or the

command prompt. In that terminal, as a first step simply run node -v, like this,

this should show you the version of nodejs you installed.

Now with that being executed, you can now use node just like that to enter a special input mode,

the so-called repl I'll come back to that where you can execute code and have it parsed by node on the

fly.

You can use this as a calculator, simply type two plus two to see the result

or you can write whole javascript programs there.

Now I won't do that

so you can quit it with control c

and instead let's write a real script which we can execute with nodejs so that we can also see what

we can do with it. For that, create a new folder anywhere on your computer and open that folder in your

favorite IDE or code editor.

Now here I am using Visual Studio code,

you can find that on code.visualstudio.com,

this is a great IDE which I strongly recommend using,

it's free,

it is really built for you such with javascript code

it will work great and you can simply download it from this page,

as I said for free, simply walk through the installer,

it's also available for Windows and so on.

Walk through the installer it gives you

and then once it's installed,

simply start it and open that new folder you created somewhere on your computer.

This will be your project folder for this very first quick app or script

we're going to write. Now your Visual Studio code might look a bit different,

I'm in fullscreen mode which is why you don't see any menu items here at the top

and I also got two important things installed here.

The first one is the theme and you can hit command shift P or control shift P on Windows to go to that

quick command interface here and there if you type theme, then you can go to the preferences color theme and

choose which theme you want to use and I'm using the dark plus theme here,

so if you want to get the exact same coloring, you can choose that.

And I also installed an extension,

you can view the extension menu by going to view extensions or if you have on the left a menu, you can

also click on the extensions tab there but view extensions will do or the shortcut you see there

and there I installed the material icon theme, this theme here. I already got that installed

and this gives me some special file icons and so on.

You don't need that,

you just can use it if you want to, you have the exact same layout and thereafter you can go back to the view

explorer here.

Now this is then my setup, I get a gitignore file here since I'll use git for version management,

you don't need that

and with that let's simply create a new file here with control n, command n or by clicking that icon

here and then simply give it any name you want, like

first-app.js, .js is of course important because we're creating a javascript app here. Now in

there,

we can run any code

nodejs is capable of executing

and for this, I will write a simple script.

I will simply write console log

hello from nodejs.

Now you could write this in the browser too, the browser would be capable of running this and it would

log thiss in the javascript console in your browser dev tools.

Now you can also execute this with nodejs though. For this,

go back to your terminal or command prompt and make sure you navigate into that new folder you created

with the help of CD and so on,

you can alternatively also go back to visual studio code and there under view,

you can open that terminal and that will give you your default system terminal already navigated into

that folder,

so that's a bit more convenient.

And then here you can run

node

and now

first-app.js,

so that filename. If you now hit enter,

you should see hello from nodejs here because this executes your code and this already shows you

that node is javascript on your computer.

This is not using a browser, it's just using the internal engine,

the extended internal javascript engine used by the browser to execute your code locally, totally outside

of a browser.

and of course we can also do more than just logging something.

Let's for example write this text to a file.

For this, we can import something from the nodejs environment,

I mentioned that it would add new features to javascript, right.

You have to import them and I'll come back to the detailed import syntax and which features exist a

little bit later,

for now just follow along to have this first quick demo and create a new constant, I'll

also give you a brief refresher about constants in Javascript in this course and then type require

fs. Fs stands for file system and this syntax simply imports some file system functionalities into this

javascript file so that we can use these functionalities there. We can now use fs write file sync here

to create a new file and this takes a couple of arguments and the first argument is the path where you

want to store that file and that also includes the file name.

Now I want to create it in that same folder so I will simply name it

hello.text for example

and the second argument is the data we want to put in there and there I'll just put hello from nodejs.

With this if we now save this and we re-execute this with node first-app.js,

you should have a hello.txt file here and this gives you the text written in there

and this is something you couldn't do in the browser because there

you can't access your local file system and obviously it's features like this which you need to then

also create a server which we don't have at this point

by the way, this is not a website obviously, it's just some utility script and this is something we can

do with nodejs.

Well this was a first quick demo, we'll learn all the cool features and how this works and what exactly this

syntax is throughout the course of course.

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.