aboutsummaryrefslogtreecommitdiff
path: root/content/posts/2020-03-30-my-love-and-hate-relationship-with-nodejs.md
diff options
context:
space:
mode:
Diffstat (limited to 'content/posts/2020-03-30-my-love-and-hate-relationship-with-nodejs.md')
-rw-r--r--content/posts/2020-03-30-my-love-and-hate-relationship-with-nodejs.md170
1 files changed, 84 insertions, 86 deletions
diff --git a/content/posts/2020-03-30-my-love-and-hate-relationship-with-nodejs.md b/content/posts/2020-03-30-my-love-and-hate-relationship-with-nodejs.md
index 47b95d5..daebb4c 100644
--- a/content/posts/2020-03-30-my-love-and-hate-relationship-with-nodejs.md
+++ b/content/posts/2020-03-30-my-love-and-hate-relationship-with-nodejs.md
@@ -5,96 +5,95 @@ date: 2020-03-30T12:00:00+02:00
5draft: false 5draft: false
6--- 6---
7 7
8Previous project I was working on was being coded in [Golang](https://golang.org/). 8Previous project I was working on was being coded in
9Also was my first project using it. And damn, that was an awesome experience. 9[Golang](https://golang.org/). Also was my first project using it. And damn,
10The whole thing is just superb. From how errors are handled. The C-like way 10that was an awesome experience. The whole thing is just superb. From how errors
11you handle compiling. The way the language is structured making it incredibly 11are handled. The C-like way you handle compiling. The way the language is
12versatile and easy to learn. 12structured making it incredibly versatile and easy to learn.
13 13
14It may cause some pain for somebody that is not used of using interfaces to map 14It may cause some pain for somebody that is not used of using interfaces to map
15JSON and doing the recompilation all the time. But we have tools like 15JSON and doing the recompilation all the time. But we have tools like
16[entr](http://eradman.com/entrproject/) and [make](https://www.gnu.org/software/make/) 16[entr](http://eradman.com/entrproject/) and
17to fix that. 17[make](https://www.gnu.org/software/make/) to fix that.
18 18
19But we are not here to talk about my undying love for **Golang**. Only in some 19But we are not here to talk about my undying love for **Golang**. Only in some
20way we probably should. It is an excellent example of how modern language 20way we probably should. It is an excellent example of how modern language should
21should be designed. And because I have used it extensively in the last couple 21be designed. And because I have used it extensively in the last couple of years
22of years this probably taints my views of other languages. And is doing me a 22this probably taints my views of other languages. And is doing me a great
23great disservice. Nevertheless, here we are. 23disservice. Nevertheless, here we are.
24 24
25About two years ago I started flirting with [Node.js](https://nodejs.org/en/) 25About two years ago I started flirting with [Node.js](https://nodejs.org/en/)
26for a project I started working on. What I wanted was to have things written 26for a project I started working on. What I wanted was to have things written in
27in a language that is widely used, and we could get additional developers for. 27a language that is widely used, and we could get additional developers for. As
28As much as **Golang** is amazing it's really hard to get developers for it. 28much as **Golang** is amazing it's really hard to get developers for it. Even
29Even now. And after playing around with it for a week I felt in love with the 29now. And after playing around with it for a week I felt in love with the speed
30speed of iteration and massive package ecosystem. Do you want SSO? You got it! 30of iteration and massive package ecosystem. Do you want SSO? You got it! Do you
31Do you want some esoteric library for something? There is a strong chance 31want some esoteric library for something? There is a strong chance somebody
32somebody wrote it. It is so extensive that you find yourself evaluating 32wrote it. It is so extensive that you find yourself evaluating packages based on
33packages based on **GitHub stars** and number of contributors. You get 33**GitHub stars** and number of contributors. You get swallowed by the vanity
34swallowed by the vanity metrics and that potentially will become the downfall 34metrics and that potentially will become the downfall of Node.js.
35of Node.js. 35
36 36Because of the sheer amount of choice I often got anxiety when choosing
37Because of the sheer amount of choice I often got anxiety when choosing 37libraries. Will I choose the correct one? Is this library something that will be
38libraries. Will I choose the correct one? Is this library something that will 38supported for a foreseeable future or not? I am used of using libraries that are
39be supported for a foreseeable future or not? I am used of using libraries that 39being in development for 10 years plus (Python, C) and that gave me some sort of
40are being in development for 10 years plus (Python, C) and that gave me some 40comfort. And it is probably unfair to Node.js and community to expect same
41sort of comfort. And it is probably unfair to Node.js and community to expect 41dedication.
42same dedication. 42
43 43Moving forward ... Work started and things were great. **Speed of iteration was
44Moving forward ... Work started and things were great. 44insane**. For some feature that I would need a day in Golang only took me hour
45**Speed of iteration was insane**. For some feature that I would need a day 45or two. I became lazy! Using packages all over the place. Falling into the same
46in Golang only took me hour or two. I became lazy! Using packages all over 46trap as others. Packages on top of packages. And [npm](https://www.npmjs.com/)
47the place. Falling into the same trap as others. Packages on top of packages. 47didn't help at all. The way that the package manager works is just
48And [npm](https://www.npmjs.com/) didn't help at all. The way that the package 48horrendous. And not allowing to have node_modules outside the project is also
49manager works is just horrendous. And not allowing to have node_modules outside 49the stupidest idea ever.
50the project is also the stupidest idea ever. 50
51 51So at that point I started feeling the technical debt that comes with Node.js
52So at that point I started feeling the technical debt that comes with Node.js 52and the whole ecosystem. What nobody tells you is that **structuring large
53and the whole ecosystem. What nobody tells you is that 53Node.js apps** is more problematic than one would think. And going microservice
54**structuring large Node.js apps** is more problematic than one would think. 54for every single thing is also a bad idea. The amount of networking you
55And going microservice for every single thing is also a bad idea. The amount 55introduce with that approach always ends up being a pain in the ass. And I don't
56of networking you introduce with that approach always ends up being a pain in 56even want to go into system administration here. The overhead is
57the ass. And I don't even want to go into system administration here. The 57insane. Package-lock.json made many days feel like living hell for me. And I
58overhead is insane. Package-lock.json made many days feel like living hell 58would eat the cost of all this if it meant for better development
59for me. And I would eat the cost of all this if it meant for better development
60experience. Well, it didn't. 59experience. Well, it didn't.
61 60
62The **lack of Typescript** support in the interpreter is still mind boggling 61The **lack of Typescript** support in the interpreter is still mind boggling to
63to me. Why haven't they added native support yet for this is beyond me?! That 62me. Why haven't they added native support yet for this is beyond me?! That would
64would have solved so many problems. Lack of type safety became a problem 63have solved so many problems. Lack of type safety became a problem somewhere in
65somewhere in the middle of the project where the codebase was sufficiently 64the middle of the project where the codebase was sufficiently large enough to
66large enough to present problems. We started adding arguments to functions 65present problems. We started adding arguments to functions and there was **no
67and there was **no way to implicitly define argument types**. And because at 66way to implicitly define argument types**. And because at that point there were
68that point there were a lot of functions, it became impossible to know what 67a lot of functions, it became impossible to know what each one accepts,
69each one accepts, development became more and more trial and error based. 68development became more and more trial and error based.
70 69
71I tried **implementing Typescript**, but that would present a large refactor 70I tried **implementing Typescript**, but that would present a large refactor
72that we were not willing to do at that point. The benefits were not enough. 71that we were not willing to do at that point. The benefits were not enough. I
73I also tried [Flow - static type checker](https://flow.org/) but implementation 72also tried [Flow - static type checker](https://flow.org/) but implementation
74was also horrible. What Typescript and Flow forces you is to have src folder 73was also horrible. What Typescript and Flow forces you is to have src folder and
75and then **transpile** your code into dist folder and run it with node. WTH is 74then **transpile** your code into dist folder and run it with node. WTH is that
76that all about. Why can't this be done in memory or some virtual file system? 75all about. Why can't this be done in memory or some virtual file system? Why? I
77Why? I see no reason why this couldn't be done like this. But it is what it is. 76see no reason why this couldn't be done like this. But it is what it is. I
78I abandoned all hope for static type checking. 77abandoned all hope for static type checking.
79 78
80One of the problems that resulted from not having interfaces or types was 79One of the problems that resulted from not having interfaces or types was
81inability to model out our data from **Elasticsearch**. I could have done 80inability to model out our data from **Elasticsearch**. I could have done a
82a **pedestrian implementation** of it, but there must be a better way of doing 81**pedestrian implementation** of it, but there must be a better way of doing
83this without resorting to some hack basically. Or maybe I haven't found a 82this without resorting to some hack basically. Or maybe I haven't found a
84solution, which is also a possibility. I have looked, though. No juice! 83solution, which is also a possibility. I have looked, though. No juice!
85 84
86**Error handling?** Is that a joke? 85**Error handling?** Is that a joke?
87 86
88Thank god for **await/async**. Without it, I would have probably just abandoned 87Thank god for **await/async**. Without it, I would have probably just abandoned
89the whole thing and went with something else like Python. That's all I am 88the whole thing and went with something else like Python. That's all I am going
90going to say about this :) 89to say about this :)
91 90
92I started asking myself a question if Node.js is actually ready to be used in 91I started asking myself a question if Node.js is actually ready to be used in a
93a **large scale applications**? And this was a totally wrong question. What I 92**large scale applications**? And this was a totally wrong question. What I
94should have been asking myself was, how to use Node.js in large scale 93should have been asking myself was, how to use Node.js in large scale
95application. And you don't get this in **marketing material** for Express or 94application. And you don't get this in **marketing material** for Express or Koa
96Koa etc. They never tell you this. Making Node.js scale on infrastructure or 95etc. They never tell you this. Making Node.js scale on infrastructure or in
97in codebase is really **more of an art than a science**. And just like with the 96codebase is really **more of an art than a science**. And just like with the
98whole JavaScript ecosystem: 97whole JavaScript ecosystem:
99 98
100- impossible to master, 99- impossible to master,
@@ -103,10 +102,9 @@ whole JavaScript ecosystem:
103- error handling is a joke, 102- error handling is a joke,
104- standards? What standards? 103- standards? What standards?
105 104
106But on the other hand. As I did, you will also learn to love it. Learn to use 105But on the other hand. As I did, you will also learn to love it. Learn to use it
107it quickly and do impossible things in crazy limited time. 106quickly and do impossible things in crazy limited time.
108 107
109I hate to admit it. But I love Node.js. Dammit, I love it :) 108I hate to admit it. But I love Node.js. Dammit, I love it :)
110 109
1112023 Update: I hate Node.js! 1102023 Update: I hate Node.js!
112