Generating a Large Size Text File with Random Words Using Node.js

This application creates a completely random 4 GB text file using the words from the Turkish word list found at https://raw.githubusercontent.com/bilalozdemir/tr-word-list/master/files/words.json, using Node.js.

Installation

  1. Clone or download this repository to your local machine.
git clone https://github.com/bsrakts/nodejs-random-word.git
  1. Ensure that Node.js is installed on your computer. If not, download and install it from the official website: https://nodejs.org/en/download/

  2. Open your terminal and navigate to the project directory.

cd random-words-generator
  1. Install the required dependencies by running the following command:
npm install
  1. Once the dependencies are installed, you can start the application by running the following command:
node index.js
  • This will create a file with randomly generated words using the Turkish word list from wordListUrl.
  • The application will write the 10 most commonly used words in the file to the console. Note that the file size will be approximately 4 GB, and the application will throw an error if the file size is smaller or if the word list is empty.

How It Works

Important Points to Note

  • The application will throw an error if the file size is less than 4 GB or if the words.json file is empty.

  • When generating the file, the length of each line is checked to ensure that each line contains only one word. If a word has a length greater than 10 MB, it will be skipped.

  • A space character is added between each word when generating the file.

  • The 10 most frequently used words are calculated based on the number of words in the file, and only words with 4 or more characters are considered.

Tech Stack

NodeJS

🔗 Links

linkedin

twitter

License

MIT