Monorepo with NPM workspaces

I recently converted a project into a Monorepo.
I had a cli part and an Astro StaticSiteGenerator part.
At some point I felt like these parts would be entangled too much so I decided to separate them. Since they were still related they should stay in one repo but have their own dependencies and separate processes. I still could have kept this in one Astro project with a cli folder but so it feels cleaner structured.

I chose NPM as my package manager since it comes bundled with node and so I decided to try out NPM workspaces as my MonoRepo approach.

So here are my takeaways

Continue reading “Monorepo with NPM workspaces”

Filter a csv file with nodejs streams

So we have a CSV file with a member list and we want to filter all empty emails.

FirstName,LastName,Email
Max,Mustermann,max@mustermann.de
Maxi,Hasnoemail,

With nodejs streams this is almost a one liner.

We will use the csv package from the CSV project which has some sophisticated packages to parse and transform csv data with nodejs streams.

npm install csv

We will further use node as ESM (ECMAScript modules) to be shiningly modern and so lets create a file: index.mjs
Note the .mjs extension, which will tell node to interprete this as ESM. (Since nodejs v12.20.0 && v14.13.0)

We import the packages and create the filesystem streams to read the file, then built a pipeline with the streams and the single steps to process the data and write the results into a new file.
Ok let’s go:

Continue reading “Filter a csv file with nodejs streams”

Synchronous http request in node.js, that you dont want, probably

Achtung dummy code!

…and so it goes Asynchronous:

 for(var i = 0; i < loop.length; i++)
 {
	var proxy = http.createClient(PORT,SERVER);
	var request = proxy.request('GET', url, 
        {
            "host": SERVER
        });
	request.end();
	...
 }

fire, fire, fire, fire

… and so it dont, Synchronous then:

var proxy = http.createClient(PORT,SERVER);
 
for(var i = 0; i < loop.length; i++)
 {
	var request = proxy.request('GET', url, 
        {
            "host": SERVER
        });
	request.end();
	...
 }

point – shoot, point – shoot, point – shoot

well i didnt know that :)