title
Node.js Crash Course Tutorial #2 - Node.js Basics

description
Hey gang, in this Node.js tutorial we'll learn the basics of Node - the global object, modules, the file system and streams & buffers. 0:00 -- node basics 2:08 -- the global object 9:21 -- modules & require 18:49 -- node & the file system (creating, reading, deleting files etc) 31:51 -- streams & buffers 🐱‍👤🐱‍👤 JOIN THE GANG - https://www.youtube.com/channel/UCW5YeuERMmlnqo4oq8vwUpg/join ---------------------------------------- 🐱‍💻 🐱‍💻 My Udemy Courses: + Modern JavaScript - https://www.thenetninja.co.uk/udemy/modern-javascript + Vue JS & Firebase - http://www.thenetninja.co.uk/udemy/vue-and-firebase + D3.js & Firebase - https://www.thenetninja.co.uk/udemy/d3-and-firebase 🐱‍💻 🐱‍💻 Course Files: https://github.com/iamshaunjp/node-crash-course 🐱‍💻 🐱‍💻 Other Related Free Courses: + Modern JavaScript Tutorial - https://www.youtube.com/playlist?list=PL4cUxeGkcC9haFPT7J25Q9GRB_ZkFrQAc + HTML & CSS Crash Course - https://www.youtube.com/playlist?list=PL4cUxeGkcC9ivBf_eKCPIAYXWzLlPAm6G 🐱‍💻 🐱‍💻 Node.js links + Download here - https://nodejs.org/en/download/

detail
{'title': 'Node.js Crash Course Tutorial #2 - Node.js Basics', 'heatmap': [{'end': 161.395, 'start': 132.259, 'weight': 0.801}, {'end': 565.884, 'start': 532.335, 'weight': 0.718}, {'end': 671.596, 'start': 584.551, 'weight': 0.877}, {'end': 824.811, 'start': 760.862, 'weight': 1}, {'end': 953.937, 'start': 915.817, 'weight': 0.709}, {'end': 1158.038, 'start': 1133.675, 'weight': 0.722}, {'end': 1258.402, 'start': 1202.066, 'weight': 0.711}, {'end': 1923.065, 'start': 1897.149, 'weight': 0.848}, {'end': 2514.914, 'start': 2456.347, 'weight': 0.812}], 'summary': 'Tutorial on node.js covers basics of running javascript files, using global objects and settimeout, modularization with imports/exports, working with files asynchronously, and utilizing streams for reading/writing large files, with practical code examples.', 'chapters': [{'end': 105.602, 'segs': [{'end': 49.614, 'src': 'embed', 'start': 23.755, 'weight': 0, 'content': [{'end': 28.276, 'text': "just to get a feel of the basics so that you're more comfortable using node.", 'start': 23.755, 'duration': 4.521}, {'end': 35.101, 'text': "so we've already seen how we can create a javascript file on our computer and then run that through node,", 'start': 29.196, 'duration': 5.905}, {'end': 39.005, 'text': 'and we do that by opening up a terminal in the project directory.', 'start': 35.101, 'duration': 3.904}, {'end': 42.147, 'text': 'now that could be an integrated terminal like this in vs code.', 'start': 39.005, 'duration': 3.142}, {'end': 48.252, 'text': 'or you could use command prompt or something else and then say node and then whatever the file is called.', 'start': 42.147, 'duration': 6.105}, {'end': 49.614, 'text': 'in this case test.', 'start': 48.252, 'duration': 1.362}], 'summary': 'Introduction to using node.js for running javascript files.', 'duration': 25.859, 'max_score': 23.755, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OIBIXYLJjsI/pics/OIBIXYLJjsI23755.jpg'}, {'end': 79.76, 'src': 'embed', 'start': 57.475, 'weight': 1, 'content': [{'end': 74.139, 'text': "i could create a function called greet and that function takes in a name parameter and over there inside the function we'll just console.log and we'll do a template string which says hello and then output the name that we take in.", 'start': 57.475, 'duration': 16.664}, {'end': 79.76, 'text': 'so this right here, by the way, a template string we can output variables inside them using this syntax.', 'start': 74.139, 'duration': 5.621}], 'summary': "Create a greet function to output 'hello' and the name parameter using a template string.", 'duration': 22.285, 'max_score': 57.475, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OIBIXYLJjsI/pics/OIBIXYLJjsI57475.jpg'}], 'start': 2.29, 'title': 'Introduction to node basics', 'summary': 'Introduces the basics of running javascript files with node, including creating functions and using template strings. it demonstrates running a file to execute the functions, showcasing usage with quantifiable examples.', 'chapters': [{'end': 105.602, 'start': 2.29, 'title': 'Introduction to node basics', 'summary': 'Introduces the basics of running javascript files with node, including creating functions and using template strings, and demonstrates running a file to execute the functions, showcasing usage with quantifiable examples.', 'duration': 103.312, 'highlights': ['Demonstration of running a JavaScript file using Node and creating and executing a function', 'Usage of template strings in JavaScript with Node', 'Step-by-step guide on running a JavaScript file with Node on the computer']}], 'duration': 103.312, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OIBIXYLJjsI/pics/OIBIXYLJjsI2290.jpg', 'highlights': ['Demonstration of running a JavaScript file using Node and creating and executing a function', 'Usage of template strings in JavaScript with Node', 'Step-by-step guide on running a JavaScript file with Node on the computer']}, {'end': 565.884, 'segs': [{'end': 161.395, 'src': 'embed', 'start': 132.259, 'weight': 4, 'content': [{'end': 140.423, 'text': 'so in node we get access to a global object with several different methods and properties attached to it that we can use out of the box.', 'start': 132.259, 'duration': 8.164}, {'end': 146.187, 'text': 'now this is a bit like the window object when we work with javascript inside the browser.', 'start': 140.423, 'duration': 5.764}, {'end': 151.349, 'text': 'so let me just bring a browser over here so we can look at this window object inside the console.', 'start': 146.187, 'duration': 5.162}, {'end': 161.395, 'text': 'so if i just type out window like this, we can see this object with a load of different properties and methods available to us inside the browser.', 'start': 151.349, 'duration': 10.046}], 'summary': "In node, we access a global object with methods and properties, similar to the browser's window object.", 'duration': 29.136, 'max_score': 132.259, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OIBIXYLJjsI/pics/OIBIXYLJjsI132259.jpg'}, {'end': 161.395, 'src': 'heatmap', 'start': 132.259, 'weight': 0.801, 'content': [{'end': 140.423, 'text': 'so in node we get access to a global object with several different methods and properties attached to it that we can use out of the box.', 'start': 132.259, 'duration': 8.164}, {'end': 146.187, 'text': 'now this is a bit like the window object when we work with javascript inside the browser.', 'start': 140.423, 'duration': 5.764}, {'end': 151.349, 'text': 'so let me just bring a browser over here so we can look at this window object inside the console.', 'start': 146.187, 'duration': 5.162}, {'end': 161.395, 'text': 'so if i just type out window like this, we can see this object with a load of different properties and methods available to us inside the browser.', 'start': 151.349, 'duration': 10.046}], 'summary': 'In node, we have access to a global object with methods and properties, similar to the window object in a browser.', 'duration': 29.136, 'max_score': 132.259, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OIBIXYLJjsI/pics/OIBIXYLJjsI132259.jpg'}, {'end': 377.717, 'src': 'embed', 'start': 349.407, 'weight': 2, 'content': [{'end': 358.612, 'text': "and in here we're going to run a function and that function is going to run every three seconds, or rather every second will do so 1000 milliseconds.", 'start': 349.407, 'duration': 9.205}, {'end': 365.536, 'text': 'so the difference between set timeout and set interval, as you probably already know, is that this keeps on running the function every one second.', 'start': 358.612, 'duration': 6.924}, {'end': 368.338, 'text': 'this is only going to run it once after three seconds.', 'start': 365.536, 'duration': 2.802}, {'end': 377.717, 'text': "okay, so now, if i go over here, i'm going to say console, dot, log in the interval like.", 'start': 368.338, 'duration': 9.379}], 'summary': 'Comparison of set timeout and set interval for running functions at specified intervals.', 'duration': 28.31, 'max_score': 349.407, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OIBIXYLJjsI/pics/OIBIXYLJjsI349407.jpg'}, {'end': 468.171, 'src': 'embed', 'start': 438.464, 'weight': 1, 'content': [{'end': 444.35, 'text': 'so i want to show you just a couple more things that are available to us in node.js without us having to do anything,', 'start': 438.464, 'duration': 5.886}, {'end': 448.515, 'text': 'and that is two properties the dir name or directory name and the file name.', 'start': 444.35, 'duration': 4.165}, {'end': 459.485, 'text': "so let me log both of these to the console and it's underscore underscore name, and then I'm going to duplicate that and change this to file name.", 'start': 448.515, 'duration': 10.97}, {'end': 468.171, 'text': 'and what these two things do for us is, first of all, this one do name gets us the absolute path of the current folder that this file is in,', 'start': 459.485, 'duration': 8.686}], 'summary': 'Node.js provides dir name and file name properties for obtaining absolute paths.', 'duration': 29.707, 'max_score': 438.464, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OIBIXYLJjsI/pics/OIBIXYLJjsI438464.jpg'}, {'end': 529.049, 'src': 'embed', 'start': 499.068, 'weight': 0, 'content': [{'end': 503.91, 'text': "because we're sometimes interacting with different files and we need to formulate paths between them.", 'start': 499.068, 'duration': 4.842}, {'end': 506.632, 'text': 'okay, so these two are quite useful.', 'start': 503.91, 'duration': 2.722}, {'end': 512.155, 'text': 'now, like I said, the global object in node is different from the global object in window.', 'start': 507.512, 'duration': 4.643}, {'end': 519.621, 'text': "so some of the things in the window object rather most of them we can't actually access, things like DOM methods.", 'start': 512.155, 'duration': 7.466}, {'end': 529.049, 'text': "so, for example, I couldn't access the query selector, so I couldn't say console.log and then documents.queryselector.", 'start': 519.621, 'duration': 9.428}], 'summary': 'Node and window global objects differ; window object has inaccessible dom methods.', 'duration': 29.981, 'max_score': 499.068, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OIBIXYLJjsI/pics/OIBIXYLJjsI499068.jpg'}, {'end': 565.884, 'src': 'heatmap', 'start': 532.335, 'weight': 0.718, 'content': [{'end': 546.422, 'text': "let me save it and try this node global and we get an error document is not defined because document is in the window object and we don't have that in the global namespace of node.js.", 'start': 532.335, 'duration': 14.087}, {'end': 552.985, 'text': "but that's okay, because we don't really need to do all of that stuff that we want to do in a window, like interact with a web page.", 'start': 546.422, 'duration': 6.563}, {'end': 560.329, 'text': "we're going to be using node.js on the back end or on the server side, so we don't need access to all of those things available on the window object.", 'start': 552.985, 'duration': 7.344}, {'end': 565.884, 'text': 'All right, then.', 'start': 565.464, 'duration': 0.42}], 'summary': "Node.js does not have access to 'document' in the global namespace, which is not required for server-side operations.", 'duration': 33.549, 'max_score': 532.335, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OIBIXYLJjsI/pics/OIBIXYLJjsI532335.jpg'}], 'start': 105.602, 'title': 'Using node.js global object and javascript settimeout', 'summary': 'Introduces the global object in node.js, demonstrating its methods and properties like settimeout and alert, and showcases the usage of settimeout and setinterval in javascript, highlighting their differences and practical usage, with console logging demonstrations.', 'chapters': [{'end': 330.415, 'start': 105.602, 'title': 'Node.js global object', 'summary': 'Introduces the use of the global object in node.js, which provides access to various methods and properties, similar to the window object in a browser, allowing for the execution of functions like settimeout and alert, and demonstrates the usage of the global object by creating and running a global.js file.', 'duration': 224.813, 'highlights': ['The global object in Node.js provides access to various methods and properties, similar to the window object in a browser.', 'Demonstrates the usage of the global object by creating and running a global.js file.', 'The chapter illustrates the usage of the setTimeout method available in the global object of Node.js.']}, {'end': 438.464, 'start': 330.415, 'title': 'Using settimeout and setinterval in javascript', 'summary': 'Demonstrates the use of settimeout and setinterval in javascript, showcasing the difference between the two methods and how to effectively use them to run functions at specified intervals, with a demonstration of logging output to the console every second and after three seconds.', 'duration': 108.049, 'highlights': ['The difference between setTimeout and setInterval', 'Demonstration of using setInterval to run a function every second', 'Using clearInterval to stop the continuous running of setInterval']}, {'end': 565.884, 'start': 438.464, 'title': 'Node.js global object', 'summary': 'Discusses the global object in node.js, showcasing the use of __dirname and __filename properties to obtain the absolute paths of the current directory and the file, illustrating their utility in formulating paths in node.js, and highlighting the differences between the global object in node.js and the window object, emphasizing that certain window object methods are inaccessible in the global namespace of node.js.', 'duration': 127.42, 'highlights': ['The __dirname property in Node.js retrieves the absolute path of the current folder, demonstrated by outputting the full absolute path of the directory using console.log.', 'The __filename property in Node.js obtains the absolute path of the folder with the file name added on, showcased by displaying the absolute path with the file name using console.log.', 'The utility of __dirname and __filename properties is highlighted in formulating paths between different files in Node.js, essential for interacting with various files.', "The differences between the global object in Node.js and the window object are explained, emphasizing that certain window object methods, such as DOM methods, are inaccessible in the global namespace of Node.js, as demonstrated by attempting to access document.queryselector, resulting in an error of 'document is not defined' in the node environment."]}], 'duration': 460.282, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OIBIXYLJjsI/pics/OIBIXYLJjsI105602.jpg', 'highlights': ["The differences between the global object in Node.js and the window object are explained, emphasizing that certain window object methods, such as DOM methods, are inaccessible in the global namespace of Node.js, as demonstrated by attempting to access document.queryselector, resulting in an error of 'document is not defined' in the node environment.", 'The utility of __dirname and __filename properties is highlighted in formulating paths between different files in Node.js, essential for interacting with various files.', 'Demonstration of using setInterval to run a function every second', 'The difference between setTimeout and setInterval', 'The global object in Node.js provides access to various methods and properties, similar to the window object in a browser.']}, {'end': 1226.893, 'segs': [{'end': 671.596, 'src': 'heatmap', 'start': 584.551, 'weight': 0.877, 'content': [{'end': 594.838, 'text': "so what i've done to demonstrate this is create two new files modules and people and the first thing i'm going to do is just paste in a bit of data into this constant right here people,", 'start': 584.551, 'duration': 10.287}, {'end': 596.319, 'text': 'into the people file.', 'start': 594.838, 'duration': 1.481}, {'end': 603.644, 'text': "so this is just an array of strings which are people's names, and i'm also going to log those to the console down here.", 'start': 596.319, 'duration': 7.325}, {'end': 607.486, 'text': "so console.log people and i'm going to save it.", 'start': 603.644, 'duration': 3.842}, {'end': 612.948, 'text': 'now, what if i want to import this people file into this modules file?', 'start': 607.486, 'duration': 5.462}, {'end': 616.209, 'text': 'well, i can do that using a require statement.', 'start': 612.948, 'duration': 3.261}, {'end': 620.391, 'text': 'now the way this looks is by saying const and then giving this constant a name.', 'start': 616.209, 'duration': 4.182}, {'end': 621.911, 'text': 'you can call it whatever you want.', 'start': 620.391, 'duration': 1.52}, {'end': 633.741, 'text': "i'm going to call it xyz and set it equal to require, and this inside is going to be a relative path to whatever file we want to require or import.", 'start': 621.911, 'duration': 11.83}, {'end': 641.97, 'text': "now we're going to say dot forward slash, and that means look in the same directory that this file is in, since that's where the people file is,", 'start': 633.741, 'duration': 8.229}, {'end': 644.293, 'text': 'and then we want to get the people file.', 'start': 641.97, 'duration': 2.323}, {'end': 651.019, 'text': "so now we're requiring or importing this file into modules.", 'start': 645.294, 'duration': 5.725}, {'end': 653.841, 'text': "so if i run this modules file, what's going to happen?", 'start': 651.019, 'duration': 2.822}, {'end': 662.228, 'text': "well, let's take a look node modules, and now we see this array logged to the console, and that's because we log it right here.", 'start': 653.841, 'duration': 8.387}, {'end': 671.596, 'text': 'so when we require another file, automatically node looks for that file, it finds it and it runs that file, which is why we see this log down here,', 'start': 662.228, 'duration': 9.368}], 'summary': 'Demonstrated importing data from people file to modules using require statement and logging the array to console.', 'duration': 87.045, 'max_score': 584.551, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OIBIXYLJjsI/pics/OIBIXYLJjsI584551.jpg'}, {'end': 633.741, 'src': 'embed', 'start': 607.486, 'weight': 3, 'content': [{'end': 612.948, 'text': 'now, what if i want to import this people file into this modules file?', 'start': 607.486, 'duration': 5.462}, {'end': 616.209, 'text': 'well, i can do that using a require statement.', 'start': 612.948, 'duration': 3.261}, {'end': 620.391, 'text': 'now the way this looks is by saying const and then giving this constant a name.', 'start': 616.209, 'duration': 4.182}, {'end': 621.911, 'text': 'you can call it whatever you want.', 'start': 620.391, 'duration': 1.52}, {'end': 633.741, 'text': "i'm going to call it xyz and set it equal to require, and this inside is going to be a relative path to whatever file we want to require or import.", 'start': 621.911, 'duration': 11.83}], 'summary': "To import the 'people' file into the 'modules' file, a require statement with a relative path can be used, assigning it to a constant like 'xyz'.", 'duration': 26.255, 'max_score': 607.486, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OIBIXYLJjsI/pics/OIBIXYLJjsI607486.jpg'}, {'end': 735.921, 'src': 'embed', 'start': 707.364, 'weight': 6, 'content': [{'end': 713.848, 'text': "well, let's see console.log people and save it and then let me run this again.", 'start': 707.364, 'duration': 6.484}, {'end': 717.67, 'text': 'and no, we can see that people is not defined.', 'start': 713.848, 'duration': 3.822}, {'end': 725.114, 'text': "so just because we import a file right here doesn't automatically give us access to the things in that file.", 'start': 717.67, 'duration': 7.444}, {'end': 726.655, 'text': "we can't do that.", 'start': 725.114, 'duration': 1.541}, {'end': 729.177, 'text': 'we can only access them from inside the file.', 'start': 726.655, 'duration': 2.522}, {'end': 735.921, 'text': 'okay, so what then, if i wanted to access people inside this file?', 'start': 729.177, 'duration': 6.744}], 'summary': 'Imported file does not give automatic access to its contents.', 'duration': 28.557, 'max_score': 707.364, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OIBIXYLJjsI/pics/OIBIXYLJjsI707364.jpg'}, {'end': 787.137, 'src': 'embed', 'start': 760.862, 'weight': 5, 'content': [{'end': 770.308, 'text': 'well, we do that by saying module dot exports, and this is us saying look, i want to export something manually from this module, this file,', 'start': 760.862, 'duration': 9.446}, {'end': 776.832, 'text': 'and we set that equal to something, and whatever we set this equal to is what is going to be returned to us right here,', 'start': 770.308, 'duration': 6.524}, {'end': 780.014, 'text': 'and then this constant will be equal to that value.', 'start': 776.832, 'duration': 3.182}, {'end': 787.137, 'text': 'so if i set this equal to hello, then this xyz right here is going to be hello.', 'start': 780.014, 'duration': 7.123}], 'summary': 'Module exports allow manual export of values from a module, returning the assigned value.', 'duration': 26.275, 'max_score': 760.862, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OIBIXYLJjsI/pics/OIBIXYLJjsI760862.jpg'}, {'end': 824.811, 'src': 'heatmap', 'start': 760.862, 'weight': 1, 'content': [{'end': 770.308, 'text': 'well, we do that by saying module dot exports, and this is us saying look, i want to export something manually from this module, this file,', 'start': 760.862, 'duration': 9.446}, {'end': 776.832, 'text': 'and we set that equal to something, and whatever we set this equal to is what is going to be returned to us right here,', 'start': 770.308, 'duration': 6.524}, {'end': 780.014, 'text': 'and then this constant will be equal to that value.', 'start': 776.832, 'duration': 3.182}, {'end': 787.137, 'text': 'so if i set this equal to hello, then this xyz right here is going to be hello.', 'start': 780.014, 'duration': 7.123}, {'end': 787.857, 'text': "so let's try that.", 'start': 787.137, 'duration': 0.72}, {'end': 794.3, 'text': 'let me delete the second console log and save it and come down here and say node modules, and now we can see,', 'start': 787.857, 'duration': 6.443}, {'end': 798.441, 'text': 'first we get this logged because we do over here and then we get hello,', 'start': 794.3, 'duration': 4.141}, {'end': 805.944, 'text': 'because that is the value of module.exports and therefore that is the value of this thing right here.', 'start': 798.441, 'duration': 7.503}, {'end': 814.087, 'text': 'so if i want to export this, i just need to say module.exports is equal to people, simple as that.', 'start': 805.944, 'duration': 8.143}, {'end': 817.889, 'text': 'and now xyz is going to be equal to this thing right here.', 'start': 814.087, 'duration': 3.802}, {'end': 824.811, 'text': "people, and it doesn't matter that this is called xyz and this is called people, they don't need to be called the same thing.", 'start': 817.889, 'duration': 6.922}], 'summary': "Setting module.exports to export values, such as 'hello', with example usage of node modules.", 'duration': 63.949, 'max_score': 760.862, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OIBIXYLJjsI/pics/OIBIXYLJjsI760862.jpg'}, {'end': 953.937, 'src': 'heatmap', 'start': 915.817, 'weight': 0.709, 'content': [{'end': 925.561, 'text': 'so we can see right here this object with these two properties people and ages and we can now access both of those by saying xyz dot people,', 'start': 915.817, 'duration': 9.744}, {'end': 930.122, 'text': 'for example, and xyz dot ages.', 'start': 925.561, 'duration': 4.561}, {'end': 936.205, 'text': 'so save that and output those and we can see the output separately right here.', 'start': 930.122, 'duration': 6.083}, {'end': 944.65, 'text': 'awesome. now, a nice way to import multiple different things from a different file is to use destructuring,', 'start': 936.205, 'duration': 8.445}, {'end': 953.937, 'text': "and that looks something like this we can say an object right here and then whatever properties we want to extract from this object that's being exported.", 'start': 944.65, 'duration': 9.287}], 'summary': 'Demonstrated accessing properties and using destructuring for importing multiple things from a file.', 'duration': 38.12, 'max_score': 915.817, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OIBIXYLJjsI/pics/OIBIXYLJjsI915817.jpg'}, {'end': 1066.325, 'src': 'embed', 'start': 1013.42, 'weight': 0, 'content': [{'end': 1022.166, 'text': "so you'll see me using this kind of pattern in the future when I'm importing several different things or just maybe one thing from a different file.", 'start': 1013.42, 'duration': 8.746}, {'end': 1029.561, 'text': "so now we've seen how to export and also import our own made files.", 'start': 1023.74, 'duration': 5.821}, {'end': 1039.165, 'text': 'but node.js also comes with some core modules built into it and we can also require those as well for added functionality.', 'start': 1029.561, 'duration': 9.604}, {'end': 1051.533, 'text': "so let me down here say, for example, const os, which stands for operating system equals, to require and we're going to require the OS core module.", 'start': 1039.165, 'duration': 12.368}, {'end': 1054.636, 'text': 'so this is built in to node itself.', 'start': 1051.533, 'duration': 3.103}, {'end': 1056.617, 'text': "I don't need to create an OS file.", 'start': 1054.636, 'duration': 1.981}, {'end': 1062.022, 'text': "it's already built into node and I'm importing that into this file.", 'start': 1056.617, 'duration': 5.405}, {'end': 1066.325, 'text': 'so now down here I could say console.log OS,', 'start': 1062.022, 'duration': 4.303}], 'summary': "Demonstrated importing core module 'os' in node.js for added functionality.", 'duration': 52.905, 'max_score': 1013.42, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OIBIXYLJjsI/pics/OIBIXYLJjsI1013420.jpg'}, {'end': 1142.743, 'src': 'embed', 'start': 1133.675, 'weight': 2, 'content': [{'end': 1140.081, 'text': 'so one of the things that we can do with node is use its file system core module to do things like read files,', 'start': 1133.675, 'duration': 6.406}, {'end': 1142.743, 'text': 'create files and delete files on our computer.', 'start': 1140.081, 'duration': 2.662}], 'summary': 'Node enables file system operations like reading, creating, and deleting files.', 'duration': 9.068, 'max_score': 1133.675, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OIBIXYLJjsI/pics/OIBIXYLJjsI1133675.jpg'}, {'end': 1158.038, 'src': 'heatmap', 'start': 1133.675, 'weight': 0.722, 'content': [{'end': 1140.081, 'text': 'so one of the things that we can do with node is use its file system core module to do things like read files,', 'start': 1133.675, 'duration': 6.406}, {'end': 1142.743, 'text': 'create files and delete files on our computer.', 'start': 1140.081, 'duration': 2.662}, {'end': 1158.038, 'text': "now this ability to interact with the file system on a computer with javascript is something that can't be done without node and it's a really important feature to have for any kind of computer program or server-side code that needs to be able to do that needs to be able to read files or create files.", 'start': 1142.743, 'duration': 15.295}], 'summary': "Node's file system core module enables reading, creating, and deleting files on a computer, a crucial feature for server-side code.", 'duration': 24.363, 'max_score': 1133.675, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OIBIXYLJjsI/pics/OIBIXYLJjsI1133675.jpg'}], 'start': 565.964, 'title': 'Javascript modularization and node.js exports', 'summary': 'Covers javascript modularization, emphasizing import/export statements for reusable code, and importing/exporting data between files. it also explains node.js module exports, including single and multiple exports, destructuring imports, and using core modules like os. additionally, it demonstrates the file system module for file operations.', 'chapters': [{'end': 805.944, 'start': 565.964, 'title': 'Javascript code modularization', 'summary': 'Explains how to modularize code in javascript, emphasizing the use of import and export statements to create reusable and maintainable code. it also highlights the process of importing and exporting data between different files using require and module.exports, demonstrating the behavior and limitations of these techniques.', 'duration': 239.98, 'highlights': ['The process of importing and exporting data between different files using require and module.exports is explained, emphasizing the benefits of modular and maintainable code.', 'Demonstration of importing the people file into modules using a require statement is provided, showcasing the behavior of the require statement and its relationship with the file location.', 'Limitations of accessing variables from an imported file are showcased, highlighting that importing a file does not automatically provide access to its content from another file.', 'The manual export process using module.exports is demonstrated, showing how to export data from a module and assign it to a constant in another file.']}, {'end': 1226.893, 'start': 805.944, 'title': 'Node.js file system and module exports', 'summary': 'Explains how to export modules in node.js, including single and multiple exports, and demonstrates importing using destructuring. it also covers importing core modules like os and using its methods, as well as demonstrating the file system module for reading, creating, and deleting files.', 'duration': 420.949, 'highlights': ['The chapter explains how to export modules in Node.js, including single and multiple exports.', 'Demonstrates importing using destructuring and accessing core modules like OS.', 'Demonstrates using the file system module for reading files and interacting with the file system.']}], 'duration': 660.929, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OIBIXYLJjsI/pics/OIBIXYLJjsI565964.jpg', 'highlights': ['The process of importing and exporting data between different files using require and module.exports is explained, emphasizing the benefits of modular and maintainable code.', 'The chapter explains how to export modules in Node.js, including single and multiple exports.', 'Demonstrates using the file system module for reading files and interacting with the file system.', 'Demonstration of importing the people file into modules using a require statement is provided, showcasing the behavior of the require statement and its relationship with the file location.', 'Demonstrates importing using destructuring and accessing core modules like OS.', 'The manual export process using module.exports is demonstrated, showing how to export data from a module and assign it to a constant in another file.', 'Limitations of accessing variables from an imported file are showcased, highlighting that importing a file does not automatically provide access to its content from another file.']}, {'end': 1892.467, 'segs': [{'end': 1258.402, 'src': 'embed', 'start': 1226.893, 'weight': 0, 'content': [{'end': 1232.754, 'text': 'The second argument is a function and this function will fire when this is complete.', 'start': 1226.893, 'duration': 5.861}, {'end': 1238.976, 'text': 'so this method right here is asynchronous and that basically means that it takes some time to do.', 'start': 1233.374, 'duration': 5.602}, {'end': 1242.597, 'text': "now, once it's done, it will fire this callback function.", 'start': 1238.976, 'duration': 3.621}, {'end': 1250.98, 'text': 'okay, and inside this callback function we take two things an error if there was one, and also the data, the stuff that we read from the file.', 'start': 1242.597, 'duration': 8.383}, {'end': 1258.402, 'text': "so what i'd like to do first of all is check if there was an error first of all, and if there was, let's log that to the console.", 'start': 1250.98, 'duration': 7.422}], 'summary': 'Asynchronous method takes time to complete, fires callback function with error or data.', 'duration': 31.509, 'max_score': 1226.893, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OIBIXYLJjsI/pics/OIBIXYLJjsI1226893.jpg'}, {'end': 1543.802, 'src': 'embed', 'start': 1510.166, 'weight': 5, 'content': [{'end': 1512.807, 'text': "so there we go, that's writing files again.", 'start': 1510.166, 'duration': 2.641}, {'end': 1515.016, 'text': 'really simple to do All right.', 'start': 1512.807, 'duration': 2.209}, {'end': 1518.157, 'text': 'so down here let me talk about how we work with directories.', 'start': 1515.016, 'duration': 3.141}, {'end': 1523.078, 'text': 'So say, for example, I want to create a new folder called Assets or something like that.', 'start': 1518.837, 'duration': 4.241}, {'end': 1528.579, 'text': 'Well, I can do that by using a method on the FS module called mkdir.', 'start': 1523.598, 'duration': 4.981}, {'end': 1530.079, 'text': 'That stands for make directory.', 'start': 1528.619, 'duration': 1.46}, {'end': 1533.26, 'text': 'And this is going to make a directory for us.', 'start': 1530.779, 'duration': 2.481}, {'end': 1536.48, 'text': 'We just need to specify what directory to make and where.', 'start': 1533.6, 'duration': 2.88}, {'end': 1543.802, 'text': "So I'm going to say make it in the current directory, dot forward slash, then create a directory called Assets.", 'start': 1536.9, 'duration': 6.902}], 'summary': "Using fs module to create a new folder called 'assets' in the current directory.", 'duration': 33.636, 'max_score': 1510.166, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OIBIXYLJjsI/pics/OIBIXYLJjsI1510166.jpg'}, {'end': 1837.809, 'src': 'embed', 'start': 1809.501, 'weight': 6, 'content': [{'end': 1816.342, 'text': "but now this is going to look for this delete me file and if it exists, we're going to fire some code.", 'start': 1809.501, 'duration': 6.841}, {'end': 1818.763, 'text': 'and now I want to delete that file.', 'start': 1816.342, 'duration': 2.421}, {'end': 1821.603, 'text': 'and we do that by saying fs.unlink.', 'start': 1818.763, 'duration': 2.84}, {'end': 1824.344, 'text': 'that is the method we use to delete a file.', 'start': 1821.603, 'duration': 2.741}, {'end': 1833.688, 'text': "So this time I want to specify that I want to delete the file which is in the docs folder and it's delete me.txt.", 'start': 1824.964, 'duration': 8.724}, {'end': 1837.809, 'text': 'and then the second argument is a callback function.', 'start': 1833.688, 'duration': 4.121}], 'summary': "Code searches for 'delete me' file and executes fs.unlink method to delete it from the 'docs' folder.", 'duration': 28.308, 'max_score': 1809.501, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OIBIXYLJjsI/pics/OIBIXYLJjsI1809501.jpg'}, {'end': 1897.149, 'src': 'embed', 'start': 1865.813, 'weight': 4, 'content': [{'end': 1867.113, 'text': "We're not going to run the code.", 'start': 1865.813, 'duration': 1.3}, {'end': 1871.335, 'text': "So i'm going to say node files and it's going to delete that over there.", 'start': 1867.113, 'duration': 4.222}, {'end': 1876.258, 'text': "But if I run it again, we don't get an error or anything because it's not running this code.", 'start': 1871.335, 'duration': 4.923}, {'end': 1885.442, 'text': "So if I create it again, new file, delete me dot txt and try that again node files it's going to delete it for me.", 'start': 1876.258, 'duration': 9.184}, {'end': 1887.083, 'text': 'okay, cool.', 'start': 1885.442, 'duration': 1.641}, {'end': 1892.467, 'text': "so that's how simple it is to work with the file system in node.js.", 'start': 1887.083, 'duration': 5.384}, {'end': 1897.149, 'text': "now, all of what I've shown you here works really well for small files like we have.", 'start': 1892.467, 'duration': 4.682}], 'summary': 'Demonstrating file system in node.js, easily deleting files.', 'duration': 31.336, 'max_score': 1865.813, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OIBIXYLJjsI/pics/OIBIXYLJjsI1865813.jpg'}], 'start': 1226.893, 'title': 'Working with files in javascript and node.js', 'summary': 'Introduces the concept of asynchronous file reading in javascript, emphasizing error handling and data logging. it also covers working with file system in node.js, including reading and writing files, creating directories, and deleting files, highlighting the asynchronous nature of file operations and the methods involved.', 'chapters': [{'end': 1269.388, 'start': 1226.893, 'title': 'Asynchronous file reading', 'summary': 'Introduces the concept of asynchronous file reading in javascript, explaining how a callback function is used upon completion of the read operation, and emphasizes error handling and data logging.', 'duration': 42.495, 'highlights': ['The method for asynchronous file reading in JavaScript involves a callback function that executes upon completion of the read operation, thus allowing the program to continue running without waiting for the file read to finish.', 'Error handling is a key aspect of asynchronous file reading, as the callback function also captures any error that may occur during the read operation, enabling appropriate actions to be taken.', 'Logging the data read from the file is another crucial step, achieved by utilizing the callback function to access the data and output it to the console for further processing or analysis.']}, {'end': 1892.467, 'start': 1269.388, 'title': 'Working with file system in node.js', 'summary': 'Covers working with file system in node.js, including reading and writing files, creating directories, and deleting files, highlighting the asynchronous nature of file operations and the methods involved.', 'duration': 623.079, 'highlights': ['The asynchronous nature of file operations', 'Reading and writing files with Node.js', 'Creating and deleting directories', 'Deleting files in Node.js']}], 'duration': 665.574, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OIBIXYLJjsI/pics/OIBIXYLJjsI1226893.jpg', 'highlights': ['The method for asynchronous file reading in JavaScript involves a callback function that executes upon completion of the read operation, thus allowing the program to continue running without waiting for the file read to finish.', 'Error handling is a key aspect of asynchronous file reading, as the callback function also captures any error that may occur during the read operation, enabling appropriate actions to be taken.', 'Logging the data read from the file is another crucial step, achieved by utilizing the callback function to access the data and output it to the console for further processing or analysis.', 'The asynchronous nature of file operations', 'Reading and writing files with Node.js', 'Creating and deleting directories', 'Deleting files in Node.js']}, {'end': 2552.502, 'segs': [{'end': 1932.009, 'src': 'heatmap', 'start': 1892.467, 'weight': 1, 'content': [{'end': 1897.149, 'text': "now, all of what I've shown you here works really well for small files like we have.", 'start': 1892.467, 'duration': 4.682}, {'end': 1902.593, 'text': "but if we're reading from and writing to really really large files,", 'start': 1897.149, 'duration': 5.444}, {'end': 1907.496, 'text': 'then it becomes more efficient to use streams to read and write data to and from files.', 'start': 1902.593, 'duration': 4.903}, {'end': 1915.441, 'text': "so let's just take a few minutes to talk about that, right then.", 'start': 1907.496, 'duration': 7.945}, {'end': 1923.065, 'text': "so we've seen how node can read data or files from a computer now, but sometimes those files could be very, very,", 'start': 1915.441, 'duration': 7.624}, {'end': 1932.009, 'text': "very large and therefore it would take a long time to read them and we could end up waiting a while to do something with the data before it's even been fully read.", 'start': 1923.065, 'duration': 8.944}], 'summary': 'Using streams is more efficient for reading and writing large files in node.js.', 'duration': 39.542, 'max_score': 1892.467, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OIBIXYLJjsI/pics/OIBIXYLJjsI1892467.jpg'}, {'end': 1961.069, 'src': 'embed', 'start': 1935.811, 'weight': 2, 'content': [{'end': 1940.694, 'text': "so using streams, we can start using the data before it's fully been read.", 'start': 1935.811, 'duration': 4.883}, {'end': 1944.636, 'text': 'so streams work in a similar way to real life streams.', 'start': 1941.474, 'duration': 3.162}, {'end': 1949.68, 'text': 'imagine we had some kind of huge water basin or a source of water somewhere,', 'start': 1944.636, 'duration': 5.044}, {'end': 1955.024, 'text': 'and then also imagine we had a pool that needs filling up with water from that basin.', 'start': 1949.68, 'duration': 5.344}, {'end': 1961.069, 'text': 'now one option would be to get a huge tank fill it up completely with the full amount of water.', 'start': 1955.024, 'duration': 6.045}], 'summary': 'Streams allow using data before fully read, mimicking real-life water streams.', 'duration': 25.258, 'max_score': 1935.811, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OIBIXYLJjsI/pics/OIBIXYLJjsI1935811.jpg'}, {'end': 2073.817, 'src': 'embed', 'start': 2007.683, 'weight': 0, 'content': [{'end': 2019.912, 'text': "or we could pass the data a bit at a time through a stream and this way small chunks of data are packaged up into what's known as a buffer and then sent down the stream every time the buffer fills.", 'start': 2007.683, 'duration': 12.229}, {'end': 2024.216, 'text': 'so every time we get a new chunk of data from the buffer, we can start using it.', 'start': 2019.912, 'duration': 4.304}, {'end': 2030.381, 'text': "Now you get this in action when you're probably streaming something on Netflix or YouTube,", 'start': 2024.716, 'duration': 5.665}, {'end': 2033.584, 'text': 'where little bits of data are sent to the browser a bit at a time,', 'start': 2030.381, 'duration': 3.203}, {'end': 2039.509, 'text': 'so you can start watching straight away without having to wait for the whole video to load initially.', 'start': 2033.584, 'duration': 5.925}, {'end': 2042.252, 'text': "So that's the theory behind streams and buffers.", 'start': 2039.889, 'duration': 2.363}, {'end': 2043.533, 'text': "Now let's see them in action.", 'start': 2042.472, 'duration': 1.061}, {'end': 2044.926, 'text': 'Alright then.', 'start': 2044.366, 'duration': 0.56}, {'end': 2051.328, 'text': 'So there are a couple of different types of streams that I want to show you read streams and write streams.', 'start': 2045.046, 'duration': 6.282}, {'end': 2056.768, 'text': 'Now we read data via read streams and we write data via write streams pretty obvious, right?', 'start': 2051.328, 'duration': 5.44}, {'end': 2061.21, 'text': "So I've already created the streams.js file, where I'm working from,", 'start': 2057.389, 'duration': 3.821}, {'end': 2069.975, 'text': "and I've required the FS module which we will be using to create these different streams, and I've also created another document, blog3.txt,", 'start': 2061.21, 'duration': 8.765}, {'end': 2073.817, 'text': 'inside the docs folder, and this time it contains a lot more content.', 'start': 2069.975, 'duration': 3.842}], 'summary': 'Streams and buffers allow for efficient data transfer, illustrated through read and write streams in a programming example.', 'duration': 66.134, 'max_score': 2007.683, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OIBIXYLJjsI/pics/OIBIXYLJjsI2007683.jpg'}, {'end': 2514.914, 'src': 'heatmap', 'start': 2448.06, 'weight': 4, 'content': [{'end': 2453.724, 'text': 'But when we use a pipe, it must be from a readable stream To a writable one.', 'start': 2448.06, 'duration': 5.664}, {'end': 2456.347, 'text': "So let's have a look at how this works.", 'start': 2454.204, 'duration': 2.143}, {'end': 2461.892, 'text': "I'm going to comment all of that out and all I'm going to do is a comment down here to say piping,", 'start': 2456.347, 'duration': 5.545}, {'end': 2472.743, 'text': "and Then underneath I'm going to say take the read stream that we're reading data from and I want you to pipe whatever you read from the read stream into a the right stream.", 'start': 2461.892, 'duration': 10.851}, {'end': 2481.87, 'text': "so what we're doing is basically opening up this read stream reading data and every time we get a chunk under the hood it's piping that into the right stream.", 'start': 2472.743, 'duration': 9.127}, {'end': 2485.413, 'text': "so doing the same thing as what we're doing right here.", 'start': 2481.87, 'duration': 3.543}, {'end': 2488.175, 'text': 'but this is much easier to write than all of this right.', 'start': 2485.413, 'duration': 2.762}, {'end': 2496.605, 'text': "so let me now delete blog 4 just to show you that this works, and i'm going to save it and run this file again.", 'start': 2488.755, 'duration': 7.85}, {'end': 2504.491, 'text': "node streams and you'll notice we see blog 4 now and it's written all of that content to blog 4..", 'start': 2496.605, 'duration': 7.886}, {'end': 2510.573, 'text': 'now there is also another kind of stream called a duplex stream, which means we can read and write through it,', 'start': 2504.491, 'duration': 6.082}, {'end': 2514.914, 'text': 'but that is a bit beyond the scope of this lesson.', 'start': 2510.573, 'duration': 4.341}], 'summary': 'Using pipe to transfer data between streams, simplifying the process and achieving the same result.', 'duration': 24.683, 'max_score': 2448.06, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OIBIXYLJjsI/pics/OIBIXYLJjsI2448060.jpg'}, {'end': 2522.397, 'src': 'embed', 'start': 2496.605, 'weight': 7, 'content': [{'end': 2504.491, 'text': "node streams and you'll notice we see blog 4 now and it's written all of that content to blog 4..", 'start': 2496.605, 'duration': 7.886}, {'end': 2510.573, 'text': 'now there is also another kind of stream called a duplex stream, which means we can read and write through it,', 'start': 2504.491, 'duration': 6.082}, {'end': 2514.914, 'text': 'but that is a bit beyond the scope of this lesson.', 'start': 2510.573, 'duration': 4.341}, {'end': 2518.175, 'text': "so then, my friends, in this video we've seen quite a lot of the basics of node.", 'start': 2514.914, 'duration': 3.261}, {'end': 2522.397, 'text': "we've seen how to actually run code using node on our computer.", 'start': 2518.175, 'duration': 4.222}], 'summary': 'Introduction to node streams and basics of node', 'duration': 25.792, 'max_score': 2496.605, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OIBIXYLJjsI/pics/OIBIXYLJjsI2496605.jpg'}, {'end': 2552.502, 'src': 'embed', 'start': 2539.91, 'weight': 3, 'content': [{'end': 2549.519, 'text': "now, another core built-in module is the http module, and that's used to create a server, which is what is used to manage the back end of a website.", 'start': 2539.91, 'duration': 9.609}, {'end': 2552.502, 'text': "so we're going to talk about that a little bit more in the next lesson.", 'start': 2549.519, 'duration': 2.983}], 'summary': 'The http module creates servers for managing website back ends.', 'duration': 12.592, 'max_score': 2539.91, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OIBIXYLJjsI/pics/OIBIXYLJjsI2539910.jpg'}], 'start': 1892.467, 'title': 'Using streams and node.js basics', 'summary': 'Discusses using streams for reading and writing data from large files, enhancing efficiency when dealing with large files, and covers creating read and write streams in node.js with code examples and introducing the http module for server creation.', 'chapters': [{'end': 2051.328, 'start': 1892.467, 'title': 'Using streams for large file efficiency', 'summary': 'Discusses using streams to read and write data from large files, explaining how streams work in a similar way to real-life streams and how they allow for immediate use of data in smaller chunks, enhancing efficiency when dealing with large files.', 'duration': 158.861, 'highlights': ['Streams allow for immediate use of data in smaller chunks, enhancing efficiency when dealing with large files, similar to how data is streamed in platforms like Netflix or YouTube.', "Streams work in a similar way to real-life streams, allowing for data to be used before it's fully been read, thus preventing long waiting times for the entire file to be read.", 'Using streams to read and write data from large files enhances efficiency and prevents long waiting times, particularly beneficial for very large files.']}, {'end': 2552.502, 'start': 2051.328, 'title': 'Node.js streams basics', 'summary': 'Covers how to create read and write streams in node.js, demonstrating the process with code examples and explaining the concept of piping data between streams, while also introducing the http module for server creation.', 'duration': 501.174, 'highlights': ['Node.js Streams Basics', 'Introduction to Read Streams', 'Working with Write Streams', 'Understanding Piping Data', 'Introduction to HTTP Module']}], 'duration': 660.035, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OIBIXYLJjsI/pics/OIBIXYLJjsI1892467.jpg', 'highlights': ['Streams allow for immediate use of data in smaller chunks, enhancing efficiency when dealing with large files, similar to how data is streamed in platforms like Netflix or YouTube.', 'Using streams to read and write data from large files enhances efficiency and prevents long waiting times, particularly beneficial for very large files.', "Streams work in a similar way to real-life streams, allowing for data to be used before it's fully been read, thus preventing long waiting times for the entire file to be read.", 'Introduction to HTTP Module', 'Understanding Piping Data', 'Working with Write Streams', 'Introduction to Read Streams', 'Node.js Streams Basics']}], 'highlights': ['Streams allow for immediate use of data in smaller chunks, enhancing efficiency when dealing with large files, similar to how data is streamed in platforms like Netflix or YouTube.', 'The method for asynchronous file reading in JavaScript involves a callback function that executes upon completion of the read operation, thus allowing the program to continue running without waiting for the file read to finish.', 'The process of importing and exporting data between different files using require and module.exports is explained, emphasizing the benefits of modular and maintainable code.', "The differences between the global object in Node.js and the window object are explained, emphasizing that certain window object methods, such as DOM methods, are inaccessible in the global namespace of Node.js, as demonstrated by attempting to access document.queryselector, resulting in an error of 'document is not defined' in the node environment.", 'Demonstration of running a JavaScript file using Node and creating and executing a function']}