MARCIN: Hello, my name is Marcin, Chief Innovation Officer at ITMAGINATION, and I would like to invite you to our next talk from the series “Talks with ITMAGINATION Experts”. Today, we are discussing JavaScript [and Node.js]. Joining me is Artur Łabudziński. Artur, please tell us a bit about yourself.
ARTUR: I’m a Senior Software Developer and a Software Architect at ITMAGINATION. [My journey with programming] started with Turbo Pascal. I went through C, C++, PHP, and more, until I stopped with Node & JavaScript.
MARCIN: Today we’re going to focus on the topic of JavaScript. JavaScript was originally introduced as a language available mainly in web browsers, however, today it has crossed the boundaries of that world. Where can we find JavaScript today?
ARTUR: JavaScript as a language survived in browsers longer than others. Microsoft came up with e.g. Visual Basic and Basic, though they haven’t survived. It [JavaScript] survived for so long, because Ecma, an organization dedicated to standardizing communication, and in general standardization of the language [JavaScript], simply worked on the language and introduced a number of changes that were accepted by the rest or even were forced to be accepted by the others, which is why JavaScript is now identical in each browser, or at least its use is identical, which means we can use it everywhere in the same way.
People who already code in it a bit, might know jQuery which succeeded at hiding implementational differences in JavaScript between one browser and the other. Now we can use it everywhere. I’m assuming you have heard of Slack. Its PC client is written in JavaScript and runs on Electron. Telegram Desktop, Spotify Desktop – all of them are apps running in JavaScript plus HTML, and others, however mainly it's just JavaScript. It all works well, so as of now, it can run everywhere.
MARCIN: JavaScript is gaining huge popularity in backend & cloud use cases. Why is that?
ARTUR: To me, because of its speed. Because of its optimization, because Google works really hard on V8, which is the engine that runs JavaScript. They optimized it, wrote a few compilers, which is why it starts fast and also can simultaneously optimize itself because of JIT, which stands for "Just In Time compilation".
Thanks to this, we now have a decent programming language that runs everywhere. And Node, an environment for JavaScript that runs on V8 with a connection to the Operating System that allows us to write both backends and apps that are more serious, and do more than just showing a website.
MARCIN: According to AWS, 52% of all Lambdas, which are serverless functions available in AWS, are actually written in Node. Python is second, Java is third, which is liked a lot by corporations, and C# is in 4th place. Does this show the strength of JavaScript in cloud solutions?
ARTUR: It not only shows its strength, but also shows Google’s optimization efforts are paying off well because “cold start”, so Lambda’s boot, is necessary to run the script. This is why it starts so quickly, and is only getting quicker and quicker, and it’s why it’s so liked - because V8 first runs it, only then does the optimization starts.
This is perhaps the most characteristic feature of this language. It’s very fast, and runs very nicely, has a small RAM usage; at least in comparison to how it used to be, and that's mainly why it's so popular.
MARCIN: We can also write front-end and backend in the same language.
ARTUR: Correct, however Lambda here has nothing to do with it. Again, yes, we can do that, we have different frameworks for each specific purpose. Some frontend ones are Vue, React, Angular – likely the majority of us at least know them, and we also have backend frameworks that require Node.js to run.
We have Next [Next.js], Nuxt [Nuxt.js], Nest.js, some lower level libraries such as Express.js, Fastify.js, which are servers; fully-fledged web servers, something that in PHP required a separate server that ran an interpreter. Here, we – yes, Apache or Nginx – simply run our JavaScript directly that does everything itself.
Of course, that is not pure JavaScript, there is some C [in Node.js]. Node.js libraries are compiled, but they are run by Node. We have access to them in JavaScript. This is a big, cool thing; a real strength.
MARCIN: You used to be, or you are, a guardian angel of our program at ITMAGINATION which helps frontend developers, React or Angular ones, become full-stack developers in JavaScript or in TypeScript.
Please tell us how this program looks like, what it is about, and what are its results.
ARTUR: We began from me showing everybody how Node looks like, because frontend specialists mainly used Node to run their frontend apps. Most of the programmers came from a React background, so they have mainly built their project in React, and then uploaded it to a server, therefore it had to be shown how Node works, what is it, what NPM (a light package manager) can do in order to show them what can be installed, show them what can be additionally installed access to the hard drive, access to different aspects of the system, to a database, something which isn’t a thing in frontends.
We do not have to access the database, we simply connect the app to API points, so we had to teach them some backend thinking, because on the frontend, when it crashes, then it crashes for one person only.
When the backend crashes, then everybody who uses it will not be able to use it. Therefore we have a slightly bigger crash than only for one user. It had to be done, so I came up with a course for them, which, starting from the lowest level of knowledge, they will go higher and higher, level by level until they reach the level of a full API, an access to a database and a user management system.
We started with a simple API written in Express, which receives files, sends files, locks them behind a password, and does not allow you to download them if you provided a wrong password. We have done everything on files, we saved files that the user sent in a .json file in which we also had meta info such as the password, file size and a few other things. I also demonstrated that this approach is suboptimal, because you can save a password then save another password, because the previous one did not manage to save. There are several problems with such file accesses. Then we showed the transition to a database.
We used MySQL, MySQL 2 library from NPM and we simply transitioned to a database. Of course I built the database; we did not learn how to do it from scratch as it was completely unnecessary for them (I will soon explain why).
Once we did that, we had to move the metadata to the database, so the same app which was, up until this point used by the same user, suddenly received info that it has a database, that files were where they are, metadata were in the database, so it was upgraded.
Later, we switched to a full backend framework at which point we also switched from MySQL to an ORM [Object-relational Mapping]; Sequalize ORM to be precise, so it was another update; a serious one because on top of all, we introduced TypeScript to the codebase thus improving code quality. So that's why it was not necessary [high code quality] when creating this database because if we write these modules correctly, these models will pass [the tests] and will do everything for us.
Of course, we had to learn migrations and seeding, however we did not have to write too much code. And the team did it; they had some homework after I showed them how Nest [Nest.js] works, all the additional libraries, they had to rewrite the previous app using Nest & TypeScript.
After two days, everything was ready, so they started to write a real world app; our internal one. They managed to pull it off quite well, and they’re finishing up now.
MARCIN: I want to add, that the code that we created as a part of our academy is on our ITMAGINATION GitHub account.
Artur, I have one last question. If I was a dev who wished to start an adventure with full-stack development in JavaScript, what should I start it with? I will admit, that there are way too many names of libraries, projects, and products in the JavaScript world.
If you could tell us what to start with in order to not lose our minds and to use the same solutions that are widely used?
ARTUR: It’s a lot and there are constantly new [names out there]. The most important, however, is to learn JavaScript well, and I mean really well, to not have any questions about what you can do, and what you cannot do.
Then it’s good to learn TypeScript. That’s because it gives us typing; it gives us a lot of help in editors, because editors better understand our code which makes programming easier. This is important, especially for large corporate projects. I don’t even start small projects without TypeScript, because I simply know that it can grow bigger.
MARCIN: For better control, right?
ARTUR: Yes, in the editor, because it [JavaScript] does not have type control itself, however, TypeScript helps us stabilize the situation. If I started to learn now, after everything that I know, then I’d start with Express.js because it’s the most known and the simplest server framework
After that, databases. If somebody knows Postgres, then you can get PG from NPM, and if I you know MySQL, then MySQL 2. Then I’d learn an ORM – Sequelize, TypeORM, whichever one. I prefer Sequelize because it’s more comfortable for me; I simply used it more often.
Once we do that, look for a “full” backend framework such as Nest.js, Nuxt.js, or Next.js, whichever one you like more. Each of these products is actively used, if not in one corporation, then it’s used in another one. If we want to be a fullstack developer, then we want a frontend framework. The most used ones right now are Vue, React, and Angular, so whichever one. I personally prefer frameworks that are opinionated, so ones that have an opinion in themselves about how should one write code. One of them is Nest.js, and Vue is another. They have some rules how to write code, how it should be structured, and how to split it to layers. So they’re very good to use. This is why I am not particularly fond of React, because wherever you go it’s written in a different way, everybody codes as they please. They are the most used frameworks, however, so it’s good to know then even if not very well; all of them a bit, and one of them better.
MARCIN: Thank you very much Artur. I want to make a final remark, that over at ITMAGINATION we are hiring full-stack, Node, Vue, and React Developers. The links are in the description. Artur, thank you very much for your time.
ARTUR: Thank you very much, it was a pleasure. Cheers.