Hackerrank preset code

So I’m new to Hackerrank and this is my first challenge. Could somebody please explain what these blocks of code before the challenges are?

'use strict';

const fs = require('fs');


let inputString = '';
let currentLine = 0;

process.stdin.on('data', function(inputStdin) {
    inputString += inputStdin;

process.stdin.on('end', function() {
    inputString = inputString.split('\n');


function readLine() {
    return inputString[currentLine++];

Also the code below the function?

function main() {
    const ws = fs.createWriteStream(process.env.OUTPUT_PATH);

    const n = parseInt(readLine().trim(), 10);

    for (let nItr = 0; nItr < n; nItr++) {
        const firstMultipleInput = readLine().replace(/\s+$/g, '').split(' ');

        const px = parseInt(firstMultipleInput[0], 10);

        const py = parseInt(firstMultipleInput[1], 10);

        const qx = parseInt(firstMultipleInput[2], 10);

        const qy = parseInt(firstMultipleInput[3], 10);

        const result = findPoint(px, py, qx, qy);

        ws.write(result.join(' ') + '\n');


I’ve never seen things like .createWriteStream(process.env.OUTPUT_PATH) before.

They are importing and using this module: https://nodejs.dev/en/learn/the-nodejs-fs-module
It lets you interact with files.

Node.js is the backend engine that lets you run code on a server. Here it seems that HackerRank uses a Node environment to let people run their code.


The env file is also something of the backend environment, it lets you hide secrets.

You can learn more if you do the Back End Development certification in the freeCodeCamp curriculum

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.