Node.js is reducing friction when using ES modules by making it easier to get the current module directory name
![__dirname is back in Node.js with ES modules](https://programming.dev/pictrs/image/40b112a8-e023-4252-87b9-d2d446e03c02.png?format=webp&thumbnail=256)
cross-posted from: https://programming.dev/post/11927506
> Many times when I’ve tried to write some code in Node.js using ES modules I’ve found myself reaching for __dirname and then looking up how to replace it. Now Node.js, Deno and Bun support import.meta.dirname. Check out the article for more detail.
Node.js is reducing friction when using ES modules by making it easier to get the current module directory name
![__dirname is back in Node.js with ES modules](https://programming.dev/pictrs/image/8f6da63d-60f5-4230-9393-3e7b0df74f1a.png?format=webp&thumbnail=256)
Many times when I’ve tried to write some code in Node.js using ES modules I’ve found myself reaching for __dirname and then looking up how to replace it. Now Node.js, Deno and Bun support import.meta.dirname. Check out the article for more detail.
Learn how you can create a custom text-to-image generation model using JavaScript, SDXL and Replicate without needing a machine learning background or needing specialized hardware.
![Creating your own image generation model using JavaScript](https://programming.dev/pictrs/image/1649c507-febb-452a-9ed7-fdbda75cd082.png?format=webp&thumbnail=256)
The JavaScript Set was introduced to the language in the ES2015 spec, but it has always seemed incomplete. That's about to change with the addition of functions like intersection, union and difference.
![Union, intersection, difference, and more are coming to JavaScript Sets](https://programming.dev/pictrs/image/e9ec4352-d7a7-4f45-8c96-b06da6325a03.png?format=webp&thumbnail=256)
We share the biggest three issues we faced and the lessons we learned as we upgraded SonarQube to React 18.
![Lessons learned upgrading to React 18 in SonarQube](https://programming.dev/pictrs/image/dda137ae-348f-4507-91fc-89db9960b1c0.png?format=webp&thumbnail=256)
Nesting ternary operators makes code more complex and less clear. Let's investigate other ways to write conditional expressions.
![Stop nesting ternaries in JavaScript](https://programming.dev/pictrs/image/54c3daa7-a30c-44e8-9c06-e9d7f322d96e.png?format=webp&thumbnail=256)
That’s brilliant!
JavaScript's regex engine isn't the only one to have these problems. There certainly are other implementations, like Re2 and Rust's implementation, that don't have this issue. But they also lack some of the features of the JS implementation too.
While this article is about JavaScript specifically, these issues certainly exist in other regex engines too.
A deep investigation into regular expression denial of service (ReDoS) vulnerabilities in JavaScript
![A comprehensive guide to the dangers of Regular Expressions in JavaScript](https://programming.dev/pictrs/image/95837a46-0816-43df-99e7-e16360c0578f.webp?format=webp&thumbnail=256)
Ah, I didn’t realise there was a regex channel here. Thanks!
A deep investigation into regular expression denial of service (ReDoS) vulnerabilities in JavaScript
![A comprehensive guide to the dangers of Regular Expressions in JavaScript](https://programming.dev/pictrs/image/a584e87d-3d64-4343-967f-326185f5b20d.webp?format=webp&thumbnail=256)
The only real way to validate an email address is send it an email and see if it arrives! I'm sure many of us have fallen to the urge to validate an email with a regex though, and yes, it's just too dangerous! I definitely like the simplicity of checking for an @
.
I think regular expressions are actually very tempting to use because they seem hard. I feel like I go through this XKCD comic every time the opportunity to use a regex comes up. But string functions often have the answer. I hope, if this article achieves anything, it just stops people using regex to trim whitespace!
A deep investigation into regular expression denial of service (ReDoS) vulnerabilities in JavaScript
![A comprehensive guide to the dangers of Regular Expressions in JavaScript](https://programming.dev/pictrs/image/3c128c79-d383-4263-a965-a9f2a8ee4b2d.webp?format=webp&thumbnail=256)
Many popular npm packages depend on 6-8x more packages than they need to. Most of these are unnecessary polyfills and it's one of the key reasons node_modules folders are so large. The eslint ecosystem seems to be most affected by this.
![Speeding up the JavaScript ecosystem - Polyfills gone rogue](https://programming.dev/pictrs/image/3cff2db0-1152-4b7b-8097-5c21aeb5e2e2.jpeg?format=webp&thumbnail=256)
One of the most common mistakes in configuring TypeScript.
![One Thing Nobody Explained To You About TypeScript](https://programming.dev/pictrs/image/e952a2ec-afda-49f2-964a-103c280b6f68.jpeg?format=webp&thumbnail=256)
Click bait title, but this post goes into depth about using tsconfig.json correctly and across different layers of your project.
At some point in the distant past, certain Node.js projects adopted the convention of using the NODE_ENV environment variable to denote how the project was being run. For example:
TypeScript already understands JavaScript, but you can get more out of it when you add types to your JavaScript with JSDoc or TypeScript declaration files
![Typing your JavaScript without writing TypeScript](https://programming.dev/pictrs/image/5abda872-622f-4403-a7d4-ae123afa0533.webp?format=webp&thumbnail=256)
This is a follow up to my previous article on how to get more TypeScript benefits in your JavaScript. This goes into how to add types using JSDoc or TypeScript declaration files.
Grouping items in an array is one of those things you've probably done a load of times. Each time you would have written a grouping function by hand or...
![JavaScript is getting array grouping methods](https://programming.dev/pictrs/image/d7b6ab0d-8970-4085-853a-8e810354e5a5.png?format=webp&thumbnail=256)
Let's dive into what you can do to get more and more of TypeScript's benefits in your JavaScript projects.
![Get the benefits of TypeScript in your JavaScript](https://programming.dev/pictrs/image/670840f6-1018-4468-b953-24ebb595bc7f.webp?format=webp&thumbnail=256)
Node.js 20.6.0 includes built-in support for .env files
With the recent release of version 20.6.0, Node.js now has built-in support for .env files. You can now load environment variables from a .env file into...
![Node.js includes built-in support for .env files](https://programming.dev/pictrs/image/507ee2ca-105d-44cd-8d05-bd8d3645e77c.png?format=webp&thumbnail=256)
What is SAST, what does deeper SAST mean, and how does this apply to your JavaScript and TypeScript applications?
![What is deeper SAST in JavaScript?](https://programming.dev/pictrs/image/ac99e39d-4c94-4da2-9de9-f3d5df444c89.png?format=webp&thumbnail=256)
I’m writing books about TypeScript and I do workshops and trainings online and in-house. Every time I meet a new group of developers there are some TypeScript facts that they need to be confronted with:
![5 Inconvenient Truths about TypeScript](https://programming.dev/pictrs/image/1fa2f102-db51-441d-a0fc-8cd47cbc5110.jpeg?format=webp&thumbnail=256)
Generating pagination links is not as straightforward as it may seem. So, while rebuilding my own site with Astro, I released a <Pagination /> component on...
![Easy and accessible pagination links for your Astro collections](https://programming.dev/pictrs/image/b5fd468c-e3ba-4b92-aa32-16f97c019bc3.png?format=webp&thumbnail=256)
I think you're absolutely right about the difficulty for developers inadvertently getting the legacy assert behaviour. Though I hope if they do that, they at least recognise that they can use the strict
methods.
The early module had both non-strict and strict methods, even from that early time, so the original author recognised the need for using ===
, but I guess wanted to be flexible and allow for ==
usage too. Perhaps this was a bad decision, but it was made in version 0.1.21, so I would guess there was a lot of fast work going on with Node at the time and maybe not everything was thought through in as much depth as it could be. It's possible that one day the strict module may take over the place of the existing assert module, but that would be quite the breaking change!
Node.js released a new test runner in version 20. Let's dive in to how to write tests for JavaScript applications with the test runner.
![Hands on with the Node.js test runner](https://programming.dev/pictrs/image/903042b2-1713-4718-bc2f-1f5c0ab3bc63.png?format=webp&thumbnail=256)
Node.js version 20 comes with a new, built-in, stable test runner. This post takes a look into what you can do with it, with a small example test project.