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