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