Skip to content

Tag: node.js

Node.js convert directory tree to JSON

What is expected?: I would like to convert the below listed directory structure into a single JSON file. The directory structure contains JSON files that are supposed to be included in the output file as well. Limitations: Node.js Questions: What would be a good/efficient way to generate the desired output, u…

How to get all values in a data table

I am trying to get all the values in a JavaScript data table but whenever I try it says, “table.length is not a function” or, “table.size is not a function” (I’ve tried both). Here is the code I want to use: I want it to return an integer value to the console. How would I do this…

Migrating from Babel to SWC with React

TL;DR How to translate a node script like this: to use SWC instead of Babel? Context We recently upgraded our Next.js version. Next.js now supports SWC instead of Babel. The unit tests for React in our project are written with RITEway. The test command is: It transforms the files with Babel first because othe…

mongoose.connect() is undefined

I’m trying to connect to my MongoDB using Mongoose and it gives me the following error. I get this Error Answer You should change 2 things: Change { mongoose } with mongoose Remove useNewUrlParser option. New version of Mongoose does not accept it as option and it will throw an error.

Get file type using fs/node.js

I have a folder with few files and I need to get type/extension of the file matching with the number I generate in my num variable, so is there any way I can do it? My current code is: files variable return this: [‘1.jpg’, ‘2.png’, ‘3.gif’] Answer To find a file in a list o…

Count all files with specific type in folder

I’m kinda new to coding, and I need to count files with specific type in my folder, but I don’t know how to do it using fs module! My current code: Can someone help me? Answer You can use path.extname like this: Also, as mentioned by MegaMix_Craft, take care about the variable yourExtension. It ha…

Loop through pages to return all the product links

The goal is to obtain all product links from all pages in the pagination. So far I have managed to print information to the console with console.log (links). However, since I am completely new to this field and completely inexperienced, I have a problem how to pass some value back with the return command. ret…