41.How will you delete a file using Node?
Following is the syntax of the method to delete a file:
fs.unlink(path, callback)
Parameters
Here is the description of the parameters used:
path – This is the file name including path.
callback – This is the callback function which gets no arguments other than a possible exception are given to the completion callback.
42.How will you create a directory?
Following is the syntax of the method to create a directory:
fs.mkdir(path[, mode], callback)
Parameters
Here is the description of the parameters used:
path – This is the directory name including path.
mode – This is the directory permission to be set. Defaults to 0777.
callback – This is the callback function which gets no arguments other than a possible exception are given to the completion callback.
43.How will you delete a directory?
Following is the syntax of the method to remove a directory:
fs.rmdir(path, callback)
Parameters
Here is the description of the parameters used:
path – This is the directory name including path.
callback – This is the callback function which gets no arguments other than a possible exception are given to the completion callback.
44.How will you read a directory?
Following is the syntax of the method to read a directory:
fs.readdir(path, callback)
Parameters
Here is the description of the parameters used:
path – This is the directory name including path.
callback – This is the callback function which gets two arguments (err, files) where files is an array of the names of the files in the directory excluding ‘.’ and ‘..’.
45.What is the purpose of __filename variable?
The __filename represents the filename of the code being executed. This is the resolved absolute path of this code file. For a main program this is not necessarily the same filename used in the command line. The value inside a module is the path to that module file.
46.What is the purpose of __dirname variable?
The __dirname represents the name of the directory that the currently executing script resides in.
47.What is the purpose of setTimeout function?
The setTimeout(cb, ms) global function is used to run callback cb after at least ms milliseconds. The actual delay depends on external factors like OS timer granularity and system load. A timer cannot span more than 24.8 days.
This function returns an opaque value that represents the timer which can be used to clear the timer.
48.What is the purpose of clearTimeout function?
The clearTimeout( t ) global function is used to stop a timer that was previously created with setTimeout(). Here t is the timer returned by setTimeout() function.
49.What is the purpose of setInterval function?
The setInterval(cb, ms) global function is used to run callback cb repeatedly after at least ms milliseconds. The actual delay depends on external factors like OS timer granularity and system load. A timer cannot span more than 24.8 days.
This function returns an opaque value that represents the timer which can be used to clear the timer using the function clearInterval(t).
50.What is the purpose of console object?
console object is used to Used to print information on stdout and stderr.