Last active
November 1, 2021 10:45
-
-
Save kaniket7209/3f0debba010f8c87bdcb59a48b37daec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Do refer to this FAQ's also as this project mainly comprises of the concepts from the previous two videos . Solve this also... | |
1. Practical Introduction to JavaScript | |
Link - https://gist.github.com/kaniket7209/e4e36c8059287712114924ea290b2e3c | |
2. Pracatical Introduction to Node Js | |
Link - https://gist.github.com/kaniket7209/e6215aaa2f0a1c06d26f54350e601ccd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. How can you get the path of every single file present in the source directory? | |
Answer: By reading the directory first and then running a loop till its length and then use path.join() function. | |
2. How do you check whether content present inside the directory is a file or folder? | |
Answer: fs.lstatSync("path").isFile() -> to check if it's a file | |
fs.lstatSync("path").isFolder() -> to check if it's a folder | |
3. How can we escape from the error of 'File Already exists' when using "mkdir" to create directory ? | |
Answer: We can put a check of fs.existsSync("given path") before creating directory. | |
4. How can we make our commands global? | |
Answer: Just follow these steps :- | |
i) Use the shebang syntax for node i.e" #!/usr/bin/env node" . | |
ii) Run npm init -y in your terminal. | |
iii) Then you will see a package.json file . Then add "bin"={ "Your Command" : "main.js" }; inside the object . | |
iv) Now global it linking the npm . Just run npm link in your terminal and thats all now enjoy using it globally in your pc. | |
5. What if the user provides the extension that is not listed in out types object? | |
Answer: Then a new folder of name "others" will be created and files of that extension will be listed in that "others" folder. | |
6. Which function do we use to copy files from source folder to destination folder? | |
Answer: fs.copyFileSync("source_file_path" , "destination_file_path"); | |
7. What is the extra step that is needed to process cut/paste despite copy/paste ? | |
Answer: Just delete the files from source folder using "fs.unlinkSync("source_file_path")" . | |
8. What are the steps to print a tree? | |
Answer: step 1: check whether the path consists a file or folder. | |
step 2: If a file -> print it with indentation of file. | |
If a folder -> First print the folder with indentation of folder, then follow the step 1 using recursion. | |
9. What does process.cwd() returns? | |
Answer: It returns the current working directory of node.js process. | |
10. What is shebang Syntax? | |
Answer: It is nothing but the absolute path to the Bash interpreter. | |
11. Why are we using shebang Syntax in this project? | |
Answer: We are using it to tell the OS which interpreter should be used to run the commands present in the file and to global it. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. How can we take input from command line in Node.js application? | |
a) Using the object "process" | |
b) Using "input" | |
c) input:stdin(); | |
d) None of the above | |
Answer: a) Using the object "process" (process.argv[]); | |
2. Do we need path of the directory to organise a file? | |
a) true | |
b) false | |
Answer: a)true | |
3. Choose the correct option for steps in organising a file | |
step 1. copy/cut the files present in the directory to the "category folders" inside the "organised_files" . | |
step 2. identify the categories of all files present in the input directory and create a new category on basis of extensions. | |
step 3. take the input of directory path that needs to be organised. | |
step 4. create a new folder insdide the folder that user wants to oganise | |
a) step 1 -> step 2 -> step 3 -> step 4 | |
b) step 2 -> step 4 -> step 3 -> step 1 | |
c) step 3 -> step 4 -> step 2 -> step 1 | |
d) step 4 -> step 1 -> step 3 -> step 2 | |
Answer: c) step 3 -> step 4 -> step 2 -> step 1 | |
4. Do we need to require the module of node.js to access it's functionalities? | |
a) Yes | |
b) No, we get that features just by installing node. | |
Answer: Yes | |
5. How many times "organised_files" folder is made inside the directory? | |
a) Two times | |
b) Single time | |
c) It is created for every present category | |
d) No such folder is created | |
Answer: b) Single time | |
6. Is it possible to organize the folders also inside the given path or only files can be organized. If yes state the reason? | |
a) Yes , by going inside the folder using path.join | |
b) Yes , by using recursion to go perform the same operation again and again | |
c) No , its not possible | |
d) None of the above | |
Answer: b) Yes , by using recursion ,to go inside and perform the same operation again and again | |
7. Is the working of cut/paste and copy/paste functionalities are same for node.js and OS ? | |
a) true | |
b) false | |
Answer: a) true | |
8. When we copy or cut the files, we need a file of exact same name in "category_folder" as it has in source directory. How do we get that exact same name? | |
a) use path.basename("Source_file_name") | |
b) use readdirSync("Dirname__") | |
c) use path.join("directory_name", "source_file_name"); | |
d) None of the above | |
Answer: a) use path.basename("Source_file_name") | |
9. Shebang syntax is present in which of the following options? | |
a) Javascript | |
b) Unix | |
c) Golang | |
d) All of the above | |
Answer: d) All of the above | |
10. We can export any .js file/ module by using | |
a) module.export | |
b) module.exports | |
c) function.exports | |
d) fuction.export | |
Answer: b) module.exports | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment