 start-up but with good amount of funding. We are doing some good stuff with VoIP and a stack is right now about 90% JavaScript, about 10% PHP. I handle all the JavaScript parts there. I have a very good friend, Meho here who is a colleague there, who does everything else. I am stuck at it. So you can stuck at anything. So you can find me on Twitter, that weird name. I have a blog which I haven't updated in ages, but you might find some good stuff there. So basically, can you guys connect to the internet? So what I have basically done is you can find all the code that I am going to show you on that first URL. How many of you are familiar with Git? So this is on GitHub. All the code is on GitHub. What I have done is I have created like tags. So you will have to check out each tag and every step you will have a new tag. I will tell you which tag to look at. And the slide is currently running on GitHub as well. So you can find that there. Just for your information if you want to use this later. Just a disclaimer, this is not what I have made. It is like an amalgamation of at least three things that I have plagiarized. So I don't say that I have created any of these. So Node.js, cool. So what's the big deal with Node.js? So one of the major things, some of the cool things that it does is it's JavaScript. Everybody here is here because of JavaScript. The big thing thrown around that a lot of people say is it has non-blocking IO. It's even driven. It's fast and efficient. So you hear all these big terms and nobody actually tells you what they are and how they are related to JavaScript and stuff like that. So once you get the whole idea that how everything relates together, you'll have a better idea of why you should even consider. You're already familiar with so many server-side frameworks that why do you need to consider something new? It's not new, but it's new. So JavaScript, as the future says, what if JavaScript was the only thing you needed? You don't need three different languages to run your stack. JavaScript on the front end, something on the back end, something for your SQLs, something else for your deployment. Currently we are at a state where we can actually do everything in just JavaScript. Everything can be done in JavaScript. And my whole hope is that we move to a world where everything combines down to JavaScript. So you still do C++, but when you hit compile instead of creating an object file, they'll probably spit out some JavaScript and you can run it on a browser. So good things about JavaScript. A lot of people know JavaScript. It's one of those languages that people don't really learn. You have a C++ background or C sharp background. You look at the code and you're like, oh, I've seen this. This looks familiar. So nobody is, everybody's familiar, but nobody knows about it. Like, nobody learns the language. Well, that's a good start. If you're familiar, you'll be able to get to know it well faster. So there's a low barrier to entry. You can get stuff working faster. So you have all done JavaScript. So in JavaScript, most of the stuff that you do for the browser is all event based. So you have a button click, you say something dot click, and you have a handler that you wire up to it. You say whenever somebody clicks the button, go run this code. Whenever somebody does this, go run this code. Nothing is sort of flowing in one way. It's sort of a loop where everything is coming together. It's all event driven and it's natively async. Everything happens async. You do an Ajax call, let's see, async. You don't tend to do a lot of synchronous activity in the browser because the moment you do any synchronous stuff, your browser will block and your user will see that as his mouse not moved or his keyboard not working. That's bad. So everything is event based there. The last but something that is really awesome to me is team redundancy. Imagine having your server side guide and your client side guide both working in JavaScript and understanding each other's code. So in bigger, like big teams, 20, 30 people, there are 10 people just doing front end stuff. They have this small community of people who are just hacking away JavaScript. You have this other 20 people who are doing this amazing server side stuff and they're doing C-shapen. Probably both of them never talk. You could have the front end and the back end devs and anybody in between talking the same language. There's far more communication and it's easier to get things done. And then you can do stuff like what I call myself a full stack engineer. I do from like a client to the server to the database to deployment. I'm sort of doing everything. If you had everybody doing sort of everything, I guess you could go on leaves more often. So means that you can write all code in JavaScript, which is good for me. I'm a big fan of JavaScript. So it's a big thing for me. Right. So we get to the first big word, non-blocking IO. So the biggest thing that when you write like a serve networking code, most of your networking code or at least about like 75% of it has to do with something in the IO. Go get this data. Go get something from a file. Go to the internet, ping some server, get some data from it. Half of the time they spend just waiting for you. Your server isn't really doing stuff. It's just waiting for stuff. So what happens is in like the traditional sense, you write code like this. You'd say apples equals dvrock query, get me some apples. And then you'd say response dot send apples. So if you were to look at this code, right, this is how we've all learned. This is how we write code. We never think that when we come here, the process is going to stop and wait till that query completes and gets back date. You never think of it as it just happens. But there's so much stuff that goes on when that happens. And there are CPU cycles being wasted just sitting there waiting for apples to come back. Wouldn't it be cool if you know that apples will come back sometime? In the meantime, I could do something else, maybe do another request and something else or just stay idle. I don't want my CPU to spin. It's really cool. So in the traditional sense, your server would look something like that. So since when you're blocking, you can't accept another request. So if you were fetching apples and the second person comes to your server and says, okay, I want apples too. He can't get apples because you're already fetching some apples for somebody else. So the easy way of not the easy way, the way that everybody gets around this is just following thread. We have a complete new thread which can now accept a new request and hence do work. But you see these red things. So you have thread processing which is okay. It's doing some work. But you also have this thread waiting in, which is what we were talking about, getting apples, just waiting, sitting out to get the apples back. As soon as you have a huge load, let's say 1000 people come in, 10,000 people come in. So you have these 10,000 threads that are consuming memory, that are consuming all your CPU and are doing nothing. You have 10,000. If you have a super amazing server, you have 10,000 threads, but they're not doing nothing. They're just waiting for data to come back. So you can't really, truly do concurrent servers without having blocking. If you want to do it correctly, this is a way to do it, but the Node.js philosophy is that this is the wrong way to do it. The correct way would be to have a framework which doesn't block. This is able to handle more requests and somehow without blocking, it's doing all this stuff. So our server never stops. You still have things that you still have to get worked up, but you would delegate that to, let's say the OS. OS is doing all this stuff. But the server doesn't have to wait. So that can only be done if the server itself is async and it supports this whole not waiting. There's no way you can wait. You'll always do stuff. So how does Node.js get around it? So I only know Node.js is basically async. We've all seen this before. Just think of it as an HAC request. Everybody's done HAC request. So when you do an HAC request, all you do is you say what the HACs you want to do and you give it a callback or success or failure callback and you tell it that whenever my server responds, go do this. So that's exactly what it's doing. It's saying if you don't really get it, it happens. So that's within that function. It's a parameter, an anonymous function being passed. So this is our callback. So basically if you were to run this, the server would get here and then just drop through. This would be immediate. The query would be fired immediately and the code would end. You wouldn't have any sort of gate here. The server would be free to do stuff. There's no gating here. So this is how it would look. So to make all that happen, we need the other sort of big words that are thrown around. So one of them is eventing. The only way you can use callbacks is when you know when to use them. I've given you a callback, but if you don't know when should I use that callback? There's no use. You need to have events. So in event there's nothing but some interrupt coming in and telling the hey, this has happened and do something about it. So Node.js has this big huge event loop. It's a single-threaded event loop just like your browser JavaScript. So your browser JavaScript is also single-threaded. It has an event loop. So what the event loop basically does is that it always takes a little later. But it's sort of like a big overview. So if you look at this from the previous example, you had a lot of red there, and the red was back because the red was waiting. If you come here, there is no red because you never wait. It's always doing something. So even if you had like 10,000 requests, it would accept 10,000 requests. It wouldn't mean that it's processed 10,000 requests, but it has the ability to accept 10,000 requests and then serve you back whenever you get the data. And in turn, accept more requests whenever that happens. You guys have any doubts or queries about this? Confusing, not confusing. So it's not processing it one by one. Imagine it having... She saw the code, right? Imagine that for 10,000 requests, right? So the first query comes in. It just goes through because to fire the query, the server doesn't need a lot of resources. And it's free like that instant. So I'm not saying the response will come back, but at least the second person won't get like a timeout. You won't get a 504. But the OS is still spawning threads. Yeah, it will still have 10,000 threads, but the OS is doing that. Your server isn't doing it. So it won't happen that your servers does like 10,000 stuff and then this dies or it can't accept anything more. So you're sort of pushing everything and the OS is designed to do that. It knows how to do it. It's not just your app doing it. It's got like a 10,000 others stuff that it's doing. So the whole idea is that your OS knows how to do this. It's built to do this. It knows how the context is switched, right? So this will get a little bit more clear when we get to like a code example. So what if the DB or the resources configured in such a way that the DB cannot handle so many requests at that time? And it serves an interrupt saying that, okay, you... So that's another issue altogether. So that's what my server is for, in a sense. So what they would then do is that they would have like multiple servers. Obviously, you can't... If you were doing the NSSQL server, you'll have to scale up and have to have like 100 GB of RAM like a mega machine handling it. But you have stuff like, for example, you have MongoDB, which scales horizontally. So you can have like a server farm of Mongo instances running and they'll be fine. So that's scale. So that's different. And even with a traditional database server, scales vertically, you can just stick a load balance around. So you can still have like two medium sized stuff. So that's scalability. That's like another level. That's everywhere. Like what you are saying will happen even in the threading model. Like even in traditional stuff, you'll have to do extra stuff to scale. But what I'm trying to say here is that to get from 1 to 100, there is nothing. It's free here. But in the threaded model, it's not free. You have like some cost. You have to have like a good machine to handle it. But I can have a crappy old, like five years old laptop running a thousand queries easily or more because it's not doing more. Essentially, if you look at it, your server is just a proxy between your data and your app. It's not doing any computations as such unless you're doing some hyphen to math or whatever. But usually the stuff that we write at enterprise level, there's no nothing involved. It's either on the client or on like some compute server which is doing the compute. The server itself is just proxies stuff here and there. So it needs to be like really fast to handle concurrency. So the web is getting like really real time. It was okay five years ago to say, take care, I'm getting like five people. But nowadays everybody wants GNA like Google speed, right? You click and everything. So that delay should have occurred. So that's what we're trying to do. So it's what I was saying. It was designed to be highly concurrent. So scalable web apps and all that stuff really fast. So one of the reasons it's really fast is Node.js was built on top of V8. V8 is the JavaScript engine that Chrome uses. So it's built by Google. Really brainy people built it. They built something really good. So all that Node.js is basically some sugar on top of V8. So it's some libraries that can run on the super efficient VM on the server. So it's not a new framework. It's not a new language. It's not doing what other people are doing. It's just sugar to get you to write code and run stuff faster. Right now they're benchmarking it as being the fastest. Because like the new Java can use the National Engine. So I don't know like how does V8 compare to National Engine? The National Engine that the new JDK is using. This is Java expert engine. Yeah, so it is compiling the JavaScript. Yeah, but I think so that is of course Java to JavaScript. It is JavaScript to Java. JavaScript to Java? Okay. Yeah, like GD are like J, GW. GWT. They threw away GWT because they couldn't handle it. I just want to know that how does that stack up because if like Java guys are going to use it. Like how production if you ask, right, if you're on anybody on load, I mean, why Ryan Nile went with, okay, the, he spoke about Ryan? Yeah, no. Ryan is a guy who built most years, okay. He was, he started this in 2008, 2009, okay. So we had before zeroing on JavaScript, we tried Pascal, Lua and all this. The problem that had stumped him was IO. All the IOs were actually blocking which couldn't, and lack of luck, JavaScript never had any blocking IO. It was like being there 10 years. So that's why he never kind of prompt for using JavaScript out there. And the problem till, but that's playing JavaScript for three to four years of his initial, the JavaScript engine was bad. Okay, let's put the loop on it. I mean, it's really bad. With this, the V8 Chrome engine, now that changed everything. This worked quite fast. I mean, so you see, whatever is the only thing is actually right. I mean, at this, the V8 is the default standard. So if you want to go on production, it's V8. So what are you saying about it? It's not like production really. I don't know how much you're using that, what are we trying to do? So the thing is, V8 does kind of a fair amount of time on compilation. But once stuff is compiled, it runs at almost meters, meters. Yeah. So it's really fun. See the guys, they're working on that. The, Casper, the guy, performance engineer for V8 engine. Okay. So what are the, what are the mistakes that you made with the JavaScript program that you're doing? This is like a future because I keep telling people that JavaScript is really cool because so Java, as you said, had this dream that write one's compiler, write one's run everywhere. This is starting, really, really starting to do this. But if you think about it, JavaScript did it from day one. If you write JavaScript once, you can run on any damn browser. Yeah. But that's a dog. That's all the JavaScripts. Problem. So that's sort of true. Right now it's even more true because now you can run JavaScript out of a browser. So you have Node, which runs almost all platforms. And all you need to do is write JavaScript and you can run it everywhere. So what is, what is Node thrown in this at all? Is it just a, So it's just a, it's just a sugar. It's just a sugar. So people don't work with V8, right? Okay. So you're not just directly working. So it's like an API on top of it. So think of it as being like the Cadillac. V8 is just the engine. You have like a super awesome engine. You still need seat and wheels and steering wheel and brake and. But Node provides an API on top of V8. Yeah. Yeah. So it provides an API on top of V8 to access V8 plus like really good libraries. So because it's networking, they do all the low-level stuff really well. So you have, you have things like HTTP, crypto, TCP, web sockets, all the low-level networking stuff is all done. You don't have to do it again. But it also means that it's very low level. It's not like, so somebody coming from ASP.NET, for example, will be like, whoa, why do I have to write a server? I just need to write my code and put it on iOS. So here you don't have iOS. Node itself runs as a server, which is like a really powerful concept. Once you think about it, you don't have deployment. Right. You don't have to like pack your files and put it on iOS or put it on Apache or Nginx. Node itself is the server. It's your code is like tightly integrated into the server itself. So instead of having one big ass server and putting all the stuff, all the apps on it, you have tiny little servers with its own sort of, so it's more distributed and it's, you can think about stuff really fast because of it. I think I'm taking too much time. So it's really efficient because it's not blocking at all. It's doing things fast. It's asynchronous and even driven as it said. So the biggest challenge people have coming to Node.js, if you're not a JavaScript developer, is to think about async because everybody else is just stuck in the synchronous world. You're stuck to the whole idea that my IO will come back and I will use it when I want it. The moment you go async, you have to like think about it really weird because your flow of code is not linear anymore. It's like this whole big hole that you go into. They call it callback hell. It's really hell but there are like code patterns that you can use to get out of it. So a very fast introduction to what this whole event loop thing is. So think of it as you have Node app which you're writing, right? The V8 engine, right? So every time you write a Node app, it has access to the V8 engine, right? You write a function, it has a callback, right? So there is a, so all the code that you write sits in sort of like a queue. So the queue has one whole run of code, right? So if you go back to our earlier examples, dv.query, get apples and then a callback. In the first go, it would only execute dv.query, that's it, right? That's the one go that it can do. So it's that one loop, right? After the one loop, it's free. It does not do anything. Till the time somebody else comes and says, okay, I have your address, right? So that loop is, once the loop completes and Node doesn't have anything else to do, it doesn't do anything. It just sits there. So it's not sleeping. Usually you have, you have this term where you say, do something sleep and then do something else for having a date. But that sleep is more expensive because you have one thread that can potentially do stuff but it is not doing anything because of sleep, right? But in JavaScript, that's not the case. It's like a country, it's good to go. It's always in this mode where it's saying that, okay, give me something to do. So if another thing comes in, it'll just take that up and do it. If there's another dv.query, get apples, it will instantly do it and come back and say, okay, I'm done with it. And whenever our apple comes back, it knows what to do because it has a callback for it. So it's very, you know, it's essentially just a monitor on the queue. Yeah. So whatever, it's really simplistic to think about it because it's going on and on and there is a queue. Is this picking stuff out of the queue, doing it, coming back, seeing if there is anything on the queue, doing it, coming back, nothing on the queue, do nothing, right? So it's sort of what it's saying that, you know, you can have three different tasks that run three different times, but they all run sort of without any hindricks to each other. Can we have a sort of thing where the inner callback, in the scenario of a callback and sort of thing, that you have a callback which in the other resource, which again has a callback, that sort of, can we execute those two asynchronous, asynchronous, like the topmost function of the... So nothing, so because it's single threaded, it's essentially single threaded, you can never have anything in parallel, right? So you will never have, so you won't have problems either. So in concurrent systems, there is this big problem where you have parallel stuff running, right? So the problem with running parallel stuff is that you almost always have shared state, right? So you don't know if, you know, the first thread should access that, or the second thread should access that, and loads of stuff to think about when you're doing that. In this model, it's only one single thread. You are almost always, it's not always, it's 100% guaranteed that you're only doing one thing at a time, but it's doing that one thing really fast. So you can do 10 things really fast, instead of like doing 10 things parallel. So it may seem parallel, but it's asked nothing is ever parallel. It's always single. Yeah, that's loads of talk. Get down some code, right? Okay. So the way I have structured this is I have like a set of examples. And if you do have access to the internet, I really hope you can use that. You can go to that, you can go there, you can clone that repo. If you don't know, get, it's okay. You can still go to that repo. Yeah. So you can go to that repo for people who have get can clone it. Or you can always go to releases and basically just download the zip, right? So let's step on something. Just go on the whole record. Yeah, just go on the whole record. So I'll just mirror my it's easier for me to do it here. So basically one, once you've cloned it, you can, you can get to the first example by just saying get check out it. So if you have node installed on your machine right now, node has a repel. You guys know what a repel is. So it's repel is redevaluate print loop. So basically, it's like going to the browser's console. You've used deaf doors, right? So you go to the console and what you see on the console is basically a repel. You can type in JavaScript and you have to do answers. Right? So basically you can say node and it drops you to a repel. It's the weird, okay, guys can't see it. But basically it's like a prompt that comes and you can do stuff. So you can do normal JavaScript here. So you can do one plus one. And I can see it. So you can basically run JavaScript here. So you can do any sort of stuff. You can have that you can define it there and I can just say it says add as a function. So that's node in like the shortest possible thing that you can say. It's just an execution engine where you can write JavaScript and print out stuff. But it's also a lot more. It's got internal libraries that you can use. So one of the internal things that it's right now seeing. So for example, in the browser, if you were to go to the browser, do an S12, you're in console. And you can, you always have this window. Right? It's like a global object. It'll give you tons of stuff. And that's where everything resides, in a sense, all your stuff. So you can think of node having that as well. It's called process. And so you can do add this spits out like tons of stuff that you can use. So it basically has like what version of node you're running, what other native modules that it's loaded. It has all the environment available. So you can go stuff like process.env and it'll print out all your environment variables. In Windows, it'll give you all your pathways. So that's the reply. So why is this important? It's because when you're working with node, it's just like working with the browser. Many times when I'm working with JavaScript code, I just put it into the browser console to see if everything's working. So you can use that here. Right? Quit out. Right? Okay, that was the process. And since it's customary to have a hello in all programming courses, this is node's version of hello. So it's just console.log. Hello. Another thing to sort of notice here is that they have tried their level best to keep all the terminologies that JavaScript developers are already know. So they didn't have to call it console.log. They could have called it print. It would have worked as well. So you have to understand that console.log is not a JavaScript thing. That's not the language feature. It's a function that some library provides. So console.log here, node is providing you that library. So this is simplistic enough if you were to run this. So the way you run stuff in node is you say, so if you're done Python, you'll be, you'll do something of this sort when you say node. It's index. And all it does is it just says hello. That's what you do. Totally do. Right? Also, the process quits. It doesn't wait. It's done its job. So it just quits. There is no, it's not running behind sort of waiting for something to happen. It's done its stuff and it's out. Okay. So this now is a little more complex. See you, if you're familiar with JavaScript, you will also know set time. Right? So anybody care to say what this is printout? So set time out. Set time out only does one. So it's basically saying, say hello. And then after 1500 milliseconds or one and a half seconds, say hello. But something to internalize is that this code runs fast. Right? It'll do set time out. And set time out is past the call. Right? And it's told to wait that time. And obviously console.log is immediate. Right? So you can think of it as the first loop only does set time out. And that's it. And goes and keeps a pointer somewhere. Okay, after 1500 seconds, 1500 milliseconds, give me an interrupt. And it just says hello world. And then node just does whatever its own thing, right? Doesn't have to do anything till that 1500 seconds. So we'll just run this and see how that looks. It says same stuff, node index.js. You see hello later. It says hello. And sometimes later it says world. Right? I don't know why it's cutting out that screen. Okay, cool. So even this time, it did wait for a little bit of time and then it quit. Right? So this changed something smaller again. It's doing a set until. Right? Any guesses to what this will do? We already said it. But if I were to run this, it will basically keep doing that. So where are the global functions coming from? The global functions are part of node. It's, like there, it's not part of process, but it's all over the side. Oh, oh sorry. What is this invert of color? How many invert colors? It is gold red 12 pence, it is gold five red pence. Four five red pence. Black or white? Yes, sir. Where is the black and white in the red line? I think the font size is also in this. It is there in the genuine. genuine? Yes, sir. You are just having a monospace mind. Okay. Good? Okay. Cool. So, in the meantime that we were doing all that, it is still walking on its stuff. So, there is like a massive difference between the previous step and this step. That sort of tells you how node is working. The previous step, the program actually quit. This step is not quitting. Okay. Because every time it executes that one loop, there is something else in the queue. Every time set timeout is hit, it is putting something into the queue. Right? So, next event loop, it already has something to do, although it is 1500 milliseconds later. So, that queue never ends, which means that node will go on forever. But it still does not mean that it is blocking. I could still have something going on in between those 1500 milliseconds. See? See, you saw me do control C all the time. Whenever I am, it was going on and I had to do control C to get out of it. So, one of the things that people almost always get stuck on is you do all this stuff and then it is doing things and you want to sort of gracefully end stuff. You do not want somebody doing a control C and then just your server messing up something else. Okay. So, this is more UNIX kind of thing. Basically, the process variable. So, the process variable that we saw, the bigger document variable that I told you about. You can use the lights for me. Okay. Cool. Cool. Yeah. So, what this is basically saying is that whenever it gets sent, which is a control C, do something. It is basically handling input from the user and doing something about it. In this case, I am just printing something out to the console and just exiting. But you could think of it as whenever something like this happens, you could clear up stuff. Like give your program enough time to maybe close database connections, clean up some memory, do some clean up stuff before you exit. So, this time if you're on an exit, yes, still doing hello world, hello world, hello world. This time when I do control C, it will print that and then die. So, that was kind of the hello world of simplicity. You want to do something more practical. One of the things you might want to do is read a file. Everybody has files. You want your server to read a file when somebody makes a request. So, we come to one of these things you will always see, which is the require keyword. So, it's like other libraries as well when you want to bring in code that is not part of your app right now. You use a require. So, require is actually from a standard they call common JS. So, it uses common JS is required to boost. So, in this case, we are using FS, which is an inbuilt module, which is a file system module. All you're doing is you're requiring FS, which brings in FS to your app. And then you can do require FS or read file. And in our whole callback fashion, it's always async. It doesn't lock even by reading files. It will send that command out. And after it has read everything, come back with the data you want and just log it out. This is quite simple. What I've done is I have this small file data.json has a simple text in it. So, we can write again. So, all it does is it gets the text from the file and just brings it up. But it's still async. It's not blocking for that call. Okay, cool. So, we've been talking about servers till this time, but I've never shown you any code. So, this is a very simplistic web server. This is a complete web server. Can handle requests and give you a response. Everything is like 12 lines of coding. So, it's again getting in a native module. The HTTP is a native module, which comes with Node. So, what you can do is you can use the create server, create a server. And the create server takes a callback. So, what create server internally does is it does all the magic to bring up a server which is listening on a TCP socket and can accept requests. But all you need to think about is what you want to do with the request. You're not sort of thinking about how the connection is being made. That's being encapsulated from you. So, all you have to do is that once you get the request, it gives you these two objects. One is a request object, incoming request, and the outgoing response. So, on the response, you can obviously write out to the response. It'll be something that you want to send back to your user. So, I'm writing back 200. And I'm saying, so it's a right head. So, it's writing a header. I'm writing the header of content type. It's text plane. And all it does is write hello world after that and just ends. You can also see that I have something after that which is listen 3000. So, I'm basically telling it to create the server. If I were to just create the server, it wouldn't do anything. It would just create the server and exit. It's kind of pointless to have a server that's creating these things. You have to tell it to listen on some port. I'm giving it 3000. So, it does. Let's just see if it works. So, you can see that the server is running on port 3000. So, how do we sort of... So, I can bring up another term. It's a hello world to me. So, I don't know why I don't know. Hopefully, if you guys were to pin this IP, you would get a hello world as well. If you guys would. So, you can do... If you're on Unix, you can do call 172.16.145.103, 3000. And you'll get the response too. Or you can just open a browser. Put that thing in. So, you can do here and still give me a hello world. So, you can do that on a browser as well. It's trying it. Cool. So, now I'm sort of coming to the place where we can kind of see... Kind of prove in code that it is doing async stuff. It can handle more than one request right now. So, what I've done here is the same code as before. The only difference being that it will take two seconds to process your request. So, if you can see, it says hello world. And then there is a set timeout. So, effectively think of the set timeout as being an IOCOR. So, let's say I increase the timeout to five seconds. So, I increase the timeout to five seconds. It will take five seconds for it to write world. And then close the connection. So, it doesn't close the connection till you say response.n. So, I have the server running saying hello, which five seconds does world and comes back. So, if you were to think about it, this is not usually possible in HTTP. So, I come from ASP.NET. ASP.NET I couldn't do this because what ASP.NET does is buffering. So, if you have, let's say, 10 things to do. And you're waiting like one second each to do that. The server actually buffers the whole content. And then sends back everything. So, your client would sort of get, okay, I got your request. Then we'll wait whatever time, 10 seconds. And then in one whole chunk, we'll get back the response. But if you were to see here, you got hello immediately. It didn't wait for anything to happen. Obviously, world was five seconds later. So, how is that, how is it doing that? One of the things is it's setting these headers behind the scenes. And it's using something called streaming. I don't really understand exactly what streaming is. But think of it as a stream pouring water out. You're not waiting for water to collect somewhere and then giving it to you. You can keep sending stuff to your client while you're processing data, which is insanely awesome if you think about it, because if you were to do something like video streaming, you can't have the client to wait till the whole video is buffered on the client and then send it out. It's more easier to send in chunks, having to play the chunks while more chunks are being downloaded. That's how you have YouTube. Not saying it can't be done in the other things, but it's inbuilt or that's the way Node does things. It doesn't know how to buffer things at all. There is no way you can buffer things in Node. Obviously, you can write code to make it do stuff. But by default, everything happens as a stream. Everything is streaming to you. So to see what it's doing, one of the things is if you do an I. So if you see the first part we set, the 200 we set, the text plane we set, the date of the server setting, there are two things called connection and transfer end goal. So the connection keep alive tells the client that I'm not done with it. Keep me alive till I tell you that things are done. Usually what happens if you don't give that is that as soon as there is an end or there is a break in your data coming back from the server, the client will close the TCP connection because that's how it works. So you have to send it, keep alive to say that, okay, I'm not done doing it. Expect more stuff from me. In the other part, it's not done just with keep alive. You have this transfer encoding which is chunks with which sort of tells the server that expect the data coming back to be in chunks. They can be breaks. Don't worry about it. Just so the client can keep but do whatever with it. The client can probably buffer it or the client can start using it as soon as it's getting stuff. Another thing that this allows us to do is so I have two tunnels open. I have two calls and what I can now do is think of the whole whole async blabber that I've been doing till now. If I were to hit my server with one call, it would start processing that part. It's single threading. It cannot do two things at the same time. If I were to send it and we know that there's like five seconds wait between the time when things will complete. If I were to send something between that period, if all my async stuff works, I should get the hello in the other windows. That sort of tells us that node is free enough to get another request. Hopefully this works. So it handled two requests. It's single threading. You can kind of make sense of it. It's doing things really fast and it's doing async because node could do it because after doing the first hello, it's ID. Once we're done with all the request IP. Request IP. We can see stuff. Yes. Oh, you want to see who is connecting to it? Okay. So after that hello probably you can print. Okay. We'll see this. I think it was requested agent. We'll see if things work. So I'm not printing the remote address and the exact, I can Google it. Why are you not using the response dot right? So I'm not sending it to the client. So if you do response dot right, it's actually sending it to the client. So the console.log will happen on the server. So you'll see it in the server store. Okay. That's request.agent. Too many stuff open. Okay. Somebody is hitting it, but I've not put the correct property. Okay. Remote address. Remote address. Correct. Okay. This is a good time to show you guys how to debug stuff. Does the server have a node language thing? There's a JavaScript. It has JavaScript, but somebody has to write for node. JavaScript. It's a language. We didn't think all about another job. You know, like MAR and all that. No change is specific. Require, request. It's not a language stuff, right? It's low. Pardon me. Request.connection.net. So basically, all of you guys who are hitting the server are going to get everything back only in five seconds, after five seconds. It's a thing completes in five seconds, but it's able to serve everybody, even with that one single thread, because it's not waiting. It's doing that first hello, so insanely fast, where it can, you can actually do more than, I'm not too sure how many it can do, but let's say about a hundred, without... Yeah, it depends on the machine. But you can see the power, like, at this level, right? Cool. So that was for this. Yeah, I just tried it, and basically, Python ran out of threads before node stops, or everything. Oh, I could do this. I can run a benchmark. I think AB is installed. So I have a server running here. So probably to start in level mode, so we would like, starting the server in level. I'm manually starting it. So I can do... AB is like a benchmarking tool for Apache. So you can do, I think it was in 100, C, and... So basically, what this will do is, it'll make 100 requests at a concurrency of 100%. So basically it's doing 100 requests at the same time. Hopefully this doesn't crash the machine. Cool. So, if you look at the... If it were blocking, and if it were doing synchronous stuff, what you would have expected is it would have taken... It's a weight of two seconds, so it would have taken 200 seconds to finish those 100 concurrent requests. Right? But we are saying that it's async. It shouldn't take that much. All your requests should only take two seconds because it's... doing them one after the other and then managing everything. So it basically took... So it's a... Time taken for tests. 2.033 seconds. So if you think about it, the only overhead that was there, that was the actual processing that it took was a 0.33 seconds. So it did 100 requests in 0.33 seconds. The two seconds is obviously the weight that we put into them. And you can see that it completed 100 requests, nothing failed, no write errors. Yeah. Cool. So that sort of shows you how concurrent you can get with node, right? Okay, cool. Now that we have sort of seen that part, one of the things you should understand is obviously I can't keep writing my whole server in one file. Right? I would need some sort of a way to modularize my code, maybe share it with people, or just to keep sanity in my own project. Right? So the require that you see, require HTTP. You can do that for your own module. So you can write your own modules. You can write stuff that you are using as modules so that you can keep it in, like, separate separate files and then use it for, like, share it or whatever, or just keep sanity. So the way you write it, so here you can see what I have done is I have refracted the same code. It's exactly the same. There was a list in 3,000. Right? The port number was sort of hard coded there. So what we have done is I have made a small file. Right? I initialized a variable. It's an object which has port as a property and 3,000 as its value. Right? So variable and and that's it. It's really simple. So the way you tell node that you want to use another file, so if you think about it, JavaScript has this problem of global scopes. Right? You can really easily pollute your scope with any damn thing you want. Right? So when you're writing really complex code, you need, like, a very tight way of controlling what is given out from this module that you are doing. Because at the end of the day, it is a JavaScript file and a bunch of JavaScript that's getting executed. Right? So there is no way you can control stuff. So they came up with this really nice way of doing it where you define your code. Right? And then you have this special syntax if you will. There is this object called module and it has a property called exports. What basically exports is is an object that will be exported when you do a require. So is it analog or is it any analog? So whenever you require whenever that require statement is hit, it will load in the file. It will load in this JavaScript file. So if you are happening inside the function the way we do it in traditional JavaScript. You can do that as well. And then it has an object considering the things only you want at that time. But nothing will happen. If you don't use a module.exports So will that So will config be still put up somewhere? No, it won't be. So the basic idea that they have is that you can write whatever you want in the module but only the things that need to be exported will be given back to the require call. Or rather like expose. So when you saw first the when you said require, require. So it's not this line, it's that line. That is pooling in it. So whatever you are exposed bring it in here. So what are required as part of common JS? That's why we talk about global names, space pollution and all that happens because of that. So one way Ryan and all these guys you know this is a problem with JavaScript. So they've made a common JS this is mitigated. So you have your namespace, your namespace whatever garbage happens, happens in that namespace it doesn't. I mean is this sort of process once in a while? So if you, one good thing that you can say what happens? Suppose they call a require on this thing. And I call it twice twice later on. How many times will this get initialized? Only once. If you put an output statement this will be once it is already recorded. Does that initially? And that also has to do because with JavaScript it differs very significantly with Java you know you try to declare a variable as late as possible in Java. Right? There's a good problem in practice in Java at least. In JavaScript it makes no sense because we always put all the initialized stuff. Yeah if you don't take your observations and then this thing works like this query, this query Yeah. So you can have nested require. So I can require stuff from your go there load this stuff. There is also I mean if you run web script development you have to make sure your scripts are ordered. If you say yes this and your ordering load is then you get the undefined which you got. So at the end of this once you run through this and whatever has to be exported has already been exported. Is the rest of it selected or does it sort of hang around in memory? So the config will have me around in memory but the rest of it will be but in a sense if you're exporting something I'm thinking that you might have references to all those stuff as well. Whatever you're writing. No, basically the variables so if you have some complex processing in your module definition and you are just exporting part of it. So what is the part of it? Yeah, so you have internal variables Either you export an object or you export a function or whatever. So the rest of the stuff that just get garbage corrected in the end. That is actually dependent on a v8. So that's what I was trying to say as well. So let's say you have this whole I can actually go to the other part. So you guys are okay with this right? This is quite simplistic. It'll just give you back if you look at inexorges what it's doing is it'll give you back the config variable which has this config which is this which is basically config.port equals 3000 and then you can just directly use it as config.port Right? So what I've also done is remember there was this whole function inside the create server which is where you are handling all the requests. So what I've done is I've taken that refracted out that and put it into a zone file called handle. Even this it's not really clear but basically you can think of it as in my next thing I'll just show you the next thing. So it's basically the same thing, the same function instead of now being like this huge blob in index.js it's its own thing. It's one small thing that you can think about. The more code you have the more confused of it. The user file you have there's no reference to it. Can we have an array of say or the request like you haven't required this without I mean using that an array of all the requirements or a define. There are different more challenges. You're right on that. I think in packaging in the JavaScripts. That's a different. So the advantages of that are the advantages of this too. So where you require answers okay I can get all of that. Unique, lazy loonings actually. I loot those whatever I have that you require only when something has to be lazy loonings. I'll just call it when I want that thing but if you look at in web development how it happened, you know the STP makes you want to send all of these take shot because minimize you can't do it. I'm getting to like a big huge chunk of this. So what you can see here is that I have sort of increased what the handler can do now. It's doing tons of stuff right. And you see down that it's just exporting handle. I've written tons of stuff here. Handler is only this much and then all this stuff is not being exported. So once you call config handler even though the file contained all these other functions you had a route function you had a sort of static you have par csv god knows how many other functions I won't get all those functions outside. There's no way I can call anything that I've written there unless I've exported it explicitly. Going back to Chinmai's question will all the other stuff that I can't have access to is it garbage collected depends because if you see the handler is calling route and route is calling par csv and static serve so it does need to keep a reference to all that because whenever handler is called it would need access to all that. So it'll still be in memory but you just don't have access to it but let's say if I were to write something here that I don't use anyway obviously you wouldn't do that why would you want to use it? Maybe in a sense that maybe you use some function to initialize then you don't need it at all then that's a different case altogether. So this was supposed to be actually a thing that you guys can do. So if you go to step 9 you have like all the things you need for a proper web server you have request response you have you know how to read a file write a file not write a file send it back so my idea was that if you guys want you can have a go at downloading step 9 right and adding to the handler two things one thing could be a static file server so what a static file server is is you say this colon 3000 slash some filing and that file exists on your server it will just serve that file straight to you so remember in one of the previous steps I had shown you how to read a file get the data similarly you can read a file get the data write it to the response you guys want to have a go at doing that or you just want me to continue no yes or no you guys are like a voice over processing load we are still in that concurrency so there is supposed to be a workshop so the idea was that I show you stuff the use of stuff is that I keep showing you stuff you keep hearing it and then you get bored so if you want to get like your hands dirty with code you can try it out if you want otherwise I will just so I will just do it I mean just 2 milliseconds so you will get to know where it is so you can download step 9 because step 10 has the answers another question so you said require some file some module that you had right let's say on index word yes and let's say required file required and some other files so let's say you have index word yes and you have another module this other module also requires a module or whatever so is that module loaded twice in both files or no only once so it requires sort of apps like a single if you can think of a single to I am asking you guys let's say you want to access your dp you want to access it in multiple files so you will have to require that so all your data will operation so you might require it in two files so is it loaded twice so that's the reason so if you told what I said right in java you just declare available at last as possible in javascript it makes no sense you better do it at start so when it is all calling out it all maps it out and it sees ok there is a double call happening there is only one call that will actually happen that's why when I said when you have and if I put another requirement you can console log out only see one console I will keep going so that means you can basically have your database process as a single terminal and you want to preform it into that so you can basically have one session that is global to be entire so you can also have instances in a sense because you could declare your module as a class I mean javascript doesn't have a class but you could do a new on that function it has classes it has prototypical classes classes everybody is thinking of classes for example our handle is sort of trying to get a file some sort of address and we wanted that address it might be like sort of the response might change over time so we don't want that module it looks like a variable that variable is a different variable suppose it changes and that's the db connection but there is another variable the worst of the compiler v8 doesn't know what is actually db and not db you only see the variable and it makes a call so you can define it but it's not a good practice okay maybe not as complex as I said I'll go through you with you guys for doing like a simple thing let's say I wanted a logger I want to so instead of doing a console.log every time I do a console.log I want let's say a datetime stamp with that and if I wanted to put that as a module how would you do it let's say I create and I call it so basically a log console yeah it is a log function with some extra spelling is correct so you can do that so it's basically a simple function which has a property or a method called info and all it does is prints out the datetime I'm kind of making the same date so I sublime as a soul no rappel inside it so I'm sort of testing out if my code works so now this is basically my module so how do you think I should export it I need to use this in my other file that's what I do as it's a complain it is it could then do so this should give us timestamp information I have a console.log somewhere so can we overwrite console.log you can JavaScript that's one of the things you can do in JavaScript you can overwrite everything intentionally or accidentally yeah we give you a log log awesome cool so that's so we've covered sort of how you can modularize your code write your own modules it's really powerful when you do so when you actually start writing code and load it's helpful to know all these things because when I wrote my code first in load I didn't read about stuff like this so you would have like horrendous code which Mule knows about so I have like this one file which is 5000 lines and has all the routes and all the handlers everything in a single file it's only afterwards that I will oh okay you can do that yeah so yeah cool so that's modularization another thing is that you can it's got a large community node has tons of people writing good stuff for it it's like C++ if you were a C++ programmer you would have tons of libraries to use with C++ and it's powerful because it's like a huge community supporting it and the node community as well is these really enthusiastic really opinionated people who write good stuff so one way to get close this so one way to get get to know about new things code modules is they have a package management which is called NPM so node package management okay sorry my bad JS.org I had no idea what that was yeah sorry so this is maintained by the community it's got like 1000 packages now so basically if you think you need some sort of functionality check here somebody must have already written it for you just include that stuff do whatever so it's just a package management it's like apt-get for ubuntu but any idea of how much what kind of medical and scientific libraries is available not really I don't know so one thing I would say off the bat is that maybe node isn't a good place to do scientific stuff because it's very compute intensive and node is not built to be compute intensive it's more of a IO thing like if you are doing something really IO intensive do node you want to check out that as complex as possible yeah it's JavaScript unfortunately JavaScript only floats what is the numbers yeah it only floats you don't have an integer so you can't really do math correctly nothing compute so that's one pitfall so that's one pitfall there node can't do I wouldn't say node can't do but it's really hard to do yeah don't do like complex if you are able to do it then you will have a problem see a guy doing in JS JavaScript you know practice on games when they've been on that now calculation happening so that's a good thing about I mean so one of the things is that don't stick to one thing node is not the magic word can't cure everything it does what it does it does like a very limited suffers stuff where it does it well so what do you want to achieve then yeah go ahead with node but as he said he's interested in mathematical stuff I'm saying that node is the new shininess and I use node to do math may not be the correct way to go there might be other things that do really well but in terms of compute the fact that VAs is compiling everything down should actually help a lot yeah performance is a performance is a solution support is an issue see once you reach that H pay ratio you know 1 million you don't know that there is a problem there is a problem so may not be built okay good so the reason I'm showing you this is because then you can you have this whole possibility that you don't really have to do all this stuff that I did a small server that sends back stuff so just to write a small server that is sending back three things I had to write insane amounts of code and that's like a bad thing but that's the whole beauty of node it's really low level but the stuff it does internally it does it really well so you can build on so people have already built frameworks so one of the frameworks that a lot of people use is express express is a web framework it gives you you can think of it like ASP.NET MEC I keep seeing Microsoft because I wasn't Microsoft that's the world I come from so it's like ASP.NET MEC you do stuff and it renders from it renders templates and sends out views has routing has like the basics of building a web app really fast but still express is quite bad it's not like to do all of stuff but you can get started so you don't have to do low level stuff you don't have to do routes like I am doing I didn't show you this part of code but basically the way you would do routes without any framework would be request has a URL property you would have to parse the URL to see which route you are going to do like a switch case in my case do some function call based on what is being called send back the data so that's how so that's tedious you wouldn't want to do that so what you would do is you would get a library that is doing most of the stuff for you and then just think about the app that you want to write that's what everybody wants to do one question does the in-built model like the packages that might be shifting with the most very small does it cover all the booklets of my existing web servers here ASP.NET no, so it's not like ASP.NET at all it's only the think of it as like really low level stuff it will give you an HTTP module it will give you a file module it will give you a crypto really low level stuff it won't do any it doesn't say that I am going to give you a framework or how to do routing so what if we just stuff like it won't be authentic so it won't even authenticate yes you will have to put the ASP.NET on it so you are basically getting just IS and not even like IS which runs IS still have but at least IS runs doesn't even run you have to write code so I always put node.js behind nginx and offload also because it's better off that there will be some security stuff which itself is handling it so it's very very bearable I would trust someone like someone who is working node.js to do it much better off so like you said things like SSL nginx does well IS might do well so you can offload all that to nginx but the static serving nginx does well we have just been proxying here so there was this instance a few months back where we were using a version of Moody's which was actually has a certain flaw and they recommended either upgrade it immediately or use it during nginx and there was some where we were sending multiple requests once together in htp but node.js had a vulnerability which if nginx is ahead of it it would handle any character that Moody could exploit that so sometimes it's just that you as an individual or as a small team who has a limited knowledge you won't be able to handle all kind of security cases so I would as a certain like we already prefer to have an educated nginx server like nginx or apache ahead of it and let it proxy on that place but then this thing is only proxy request it's not serving anything it can serve without a problem but really depends on like we are doing apache so we don't need to serve as static assets we have an algorithm for that so that's a different thing so if you are serving it you can and nginx serves the static assets and node.js provides you the rest of the server that's how you usually go but the present consensus is the first static to be of CDN yeah and apache Moody is injects will be serving the proxy to you know the most important the first thing you do is you do the same and then you serve it so Rajesh one I'll tell you the other thing so in the ASP.NET world we sort of write everything as one big app there's no sort of smaller apps doing stuff and bringing it together and putting it something so if you were to write an MEC app the MEC app would have everything it's like a complete and then you put that one huge thing onto the server but in the node world what we are sort of or what we are doing is that we have instead of having like one big server one big app we have multiple small apps so you have one app that does just the work so our company we do we do a lot of void stuff so in a small thing if you get a call saying that sir loan sayyay it's probably some software some software that the company like ours made we don't make that but we do stuff like that where we have like a component that dials out numbers we have a component that sends messages to the client we have a component that only tells a few ring of messages so you can have different systems one small system say humans have this ability to do things well when it's really small we are really bad with sort of scope I mean some people are really good at it I have friends who can have massive scopes in their head and puke here I on the other hand can only see this much so the smaller your stuff that's why we write functions we write smaller and smaller functions smaller and smaller modules so that you make better sense of it so in the node world instead of writing like this one huge big component you write smaller small small instance servers that do specific things so you would have like a server that is an api server you would have like a messaging server you would have something that there's a dialing whatever I mean in your case it would be down to you to sort of split you could also have like one big server there's no thing saying that don't have but you could then scale better if you have smaller stuff cool so I was talking about npm so the way you bring in modules is you can say so let's say I wanted to use some package from npm where it is so maybe I wanted to use this this is a really popular package you guys have underscore this is like it's built on underscore provides better stuff for underscore a lot of people have started using low dash instead of underscore so it's a play on underscore it's low dash play on play so it's basically a utility thing you have RA iterators collection iterators all that sort and let's say I wanted to use this easiest way to do that is do this stuff so let's say I wanted to use this in my app so if you have npm installed you just say npm install npm it goes out to the internet and gets it really fast okay so it just installed an external module for me what it basically does is it just goes over the internet just gets a couple of files down okay strange let it install it so up and down why it installed it there is some trouble here but basically what it should have done is it should have added a node node underscore modules here then added the file inside that it's weird so maybe that weirdness is because there is like a sort of hierarchy that node follows when it wants to either get something or put something so the general hierarchy is you have like a system level folder node modules folder you have user levels node modules project level even like inside the project you can have multiple node modules so because it found a node modules in the upper folder we just have to put it in because what happens is you could have you could be inside you could be inside jumpstart node and inside lib and if you say npm install something it would then put a node modules inside lib which is not what you want you wanted to put it in like the project folder so I've never seen it before can you confirm that? so basically what happened was that I did a npm install there was no node modules in the current folder but there was a node modules for some reason in my parent folder which is not part of the project and it just installed it there and what do you want me to come up with? that it checks for the... is it a global install? no it isn't a global install it was in the first thing through your path and in the first node module if it found a node module in the folder first thing you look at is a .node modules if not you will go to your local and see the .node modules out there if you did a mine load as mine load g before through the modules so here it was needed not the one in the home made at the global one this was the one above in the parent directory of your code yeah that's what if you look at the root then it reaches the root there is nothing maybe it traverses back the whole way so now it's done that so it's got load as installed in our way but if you go inside load as all it has is this js file load as.js which which will be just another module see there will be a module.exports somewhere inside there it's a huge file so it's exactly like the modules we wrote but it's somebody else who's written it and you're using them it might be really complex but one good thing maybe it's because it's JavaScript you have all the source code it's open source it's like a really awesome practice which is whatever library you are walking with if it's an external library if you get the time have a go through what they've done like you learn tons of stuff like I learned that you can use modules when I looked at some modules before that I didn't because somebody sort of tells you that you can write modules so it's like an insanely good thing in the JavaScript world all the stuff is open source most of it is open source you have source code to see how everything works so now that we have load as installed I can then start using it here it will be like I was using my own module so you say whatever variable you want to give it equals to require load as right there's another thing that you can do is that when you do deploy this you have to like if you want to tell people that okay I've written this awesome piece of server you guys can use it but how do they know that what external modules are you using because you just did NPM install directly there's no way for them to like go through their job code and figure out what you're using what you're not using what needs to be installed by me so they have this they have this sort of conflict file where you can list your differences tell people that okay this module requires these modules and hence install them beforehand and then run right so you can do that easily with a package.json file it's like a big it's a JSON file it has some structure to it easiest way to make one is just say NPM init right so it'll ask you a couple of questions you answer them and it makes a package file for you same name say yeah version 1 the entry point is where your program will start so I did node index of JS is this a way for people to use NPM to start your thing rather than saying node they can say NPM start and it'll just start they don't have to know which file to use test commands I don't have any tests so obviously I can't put that it's already picked up it knows that it's a Git repo so it's picked up the you can give it keywords so usually keywords is for publishing modules so if you have a module and you want to publish it you want people to search for it so you can give some relevant keywords and after you publish it when people search for those relevant keywords they'll get your module and then it shows you what it'll look like this simplistic JSON it just has key valley pairs name what we gave it version description main is the entry point which is index.js another cool thing it did was we had already installed load hash so it's gone through my node modules figured out that I've already I'm already using these modules it's put them here and then you have these two dependencies so you have dependencies and you have depth dependencies so depth dependencies is usually things that you don't want it's things that your app really doesn't need to work but things like if you have like memory profile you have some debugger which you want to load which is only in development so you can add that as a development dependency by the way I want to on the dependencies you can have a text ahead of that which will actually signify that allow any minor version so it won't stick to 2.4.1 if the latest version is 2.4.2 it'll actually get even if you say 2.4.1 so that's like a standard semantic version 2.4.1 or higher that's what it means yeah so I have a trouble with that because I've proven with these guys that they always prefer to use that they don't pay to exact version they allow minor version to appear in the test we had trouble with that we had some issues with a couple of libraries minor version also had some changes which weren't compatible and we ran into issues and we said see I don't have test here it's a bad thing it's my fault but yeah so basically what you're saying is that when we were developing we had used a ton of external dependencies right and all the dependencies are loaded when you do an end so once you've done this what you can essentially then do is you don't need to publish your node modules folder because a node modules folder might be very mushing dependent when it was sort of installing one of your modules it would have probably done like a make install would have made a binary somewhere so you can write in C++ as well yeah actually we know that on the vc++ yeah so if you were to put node modules and publish your full app you can't just take stuff from my Linux machine and then have it run on like windows because obviously the binaries are on so the external modules always it's preferred that you do an install on your machine only the code that is pertinent to my app you need to get so even that's the reason when you do not check in with one modules so you only do this and you run it on your own on the Swiss mode so whenever I give this out to somebody all they have to do is download my code before running my code do an npm install we'll go through this file find whatever dependencies are and it will install another thing is that loadash itself will have other modules that it's dependent so you don't have to take care of that because they have a package.json as well and they will internally run through that and it will build that whole tree and give it to you and does the dependency detection tend to fail sometimes or it doesn't work pretty well no it depends if suppose some of the internet and it's potty and call an embrace it will phase and it gives you the dependency resolution itself no that is perfect that's not solid the only problem is like I see it it gives you an npm it gives you what it's calling and it will go error error error not okay and it will be there so you have to do again if you try to use automatic dependency detection in python which then is in a standard you will be doing in first place you will be running to work something no no this one is pretty solid and there is another way to start you can point anything at your project and get a list of dependencies I respect you that's fine to download stuff that's already been published but what you want to publish your own so in this way loadash got detected as a dependency how so it will detect only stuff that was there in your node modules folder if it is not there you put it somewhere else and you are requiring it from somewhere else you can't find it and what about so even if you have it in your global node modules it gets detected no so it gets detected no so it's not so I have a couple of stuff installed and pick up that it won't go to your global node so the idea is that you won't put stuff that is dependent on your in the globe even though there is a standard here everybody is going to use the volume I have put it in pygmy but something only Maya requires in that particular option so globally you would install things like you know something like a generator so you have things that generate code you have things that do you know like there is a thing called grunt build tools yeah build tools but your app doesn't need it your app doesn't need a build tool to run cool so so yeah this sort of ends my basics of node unfortunately I never got to the other parts I had three more parts of this what are they so basic express and stuff basic web sockets so anyway this is more for you guys to understand how to use not really how to get started with it but at least you know now that you can do in you probably not install node but at least how the smallest stuff works how to make your own modules how to require other modules so now that's all up to you like you have a platform to stand on you can just for example I was going to show you express right because my next slide was that by this time I had thought that everybody would be kind of blank not know what to do so it goes on to some practical stuff which is express yes you guys can look it up it's not really that difficult it's really well documented a lot of people use it express is just a way to write mvc type apps fast at the end of the time you can write like mvc premium yeah so basically you can remember how I wrote the old routes and I wrote how routes are like I'm passing routes and all that stuff inside an express all you can do is you can require express get so you can see that express is not a function it's actually a class so you can get an instance of the class so you get an app and then you can sort of declaratively put your routes so that basically reads correctly as app.get root whenever somebody hits the root of your website or web app with a get request just send a high that's all it does so you can then extend it you can go beyond express as a generator so you don't have to start doing everything on your own generators are basically code generators it will give you a template you can run command line you can just say express dash some options and your app name and a stuff for you and then you can just keep extending something like templates in mvc, mvc has these templates you can use you see a new project select a template that you want and it will give you some pre-built stuff and what do you mean what background are you coming in Microsoft yeah because if you come from Microsoft you have this created project this is a template for you or JavaScript or Java sorry gtv or gtv the idea is to have a new project but just to put it that way you know these guys are actually moving from express to something ua because apparently the way that you know they could build on top of express because they have they would be backward compatibility so they are now going on a new project and the time music right now is actually going on happy this is by Eric Hamer he works with Warped Lars and this was used for the Black Friday now if any engine can take up one month Black Friday you know it's a ship it's a bomb so there are more really more interesting stuff that you can do with Node but one big pitfall again is what he said that there is experience as well since most of the stuff is open source and most of the stuff is being maintained by like one or two guys so you have to really sort of get in there we were using API library what is it called I don't know what it was called before SFI before SFI we were using something I forgot the name so hey whoever was maintaining that it was really good I'm not saying he wrote bad code or anything it was a really good library was being used by everybody for example let's say it's Express everybody is using it it's a good library it's easy to read there is good documentation but one fine day the fellow is maintaining it decides that I'm done I'm not doing this anymore so you are kind of stuck with that whole thing that okay my app now uses this I know that I can't go ahead so one of the things you really have to do is sort of be in touch with the stuff that you are using if you are using Express try and look around what people are doing what Express is doing get more ideas of what is happening there so if we don't get involved then there is there is that thing where the person who is involved might just stop being involved then you are stuck in the loop because you were just consuming what they were saying so big companies like Microsoft won't do that because tons of money they are getting but obviously Express is not being maintained by anybody so might go away it's your holiday he actually went away so that's one thing that you have to take care of stuff that is being actively developed a lot of people are actively involved in it maybe you want to get involved in it as well and it's not that hard like Lodash Lodash is still big but maybe it's like a logger somebody might have written a logger that you are using extensively in your app loggers are like really small maybe like one file it's just because everybody gets all the front end they see the back end it requires underscore actually the reason why no one is on the scene like Lodash because it is something else that is happening in the world it's cloud computing if you see how easy it is to just create a server and do it you have to understand also if you have a sustainability and you are getting peak and run a very low level which takes minimum value setup and stuff so the scalability as you said it's really easy to scale so one of the things that they did was the low level stuff is done really well so they have this thing called cluster what you can do is you can write your node app and right now it can handle let's say x the amount of stuff on one core you have like a quad core machine it's only using one core because it's single thread you can use the cluster to easily like without much resistance scale to four cores and you have four times x capacitor put through an engine x there you can now scale to as many machines as you need with as many cores as you need so there's no limit to what you can do but it also comes with the whole headache of how you do that's the whole scalability thing if your app has state then obviously you can't scale which is what we are facing right now if one instance of the app is keeping somewhere state then you can't obviously cluster because state can't be shared between two processes you put a load value before the state has been mentioned it's in memory, it's node's memory so we need to get it out before we can so that's a scalability issue we never probably read about proper scalability that's with all probably you need to get the state into a database see what happens this is a user stack you have varnish engines then you'll have a node then you'll have memory cache if you look at the middle one then you'll have a redis then you'll have whatever database you want so I sort of took up all my time so you guys can still look at these presentations what I'll do is I'll add where I took these presentations from so maybe you'll get better context I just took like three or four different ones and combined them together into something that I could show you guys so it's online you can always look it up probably try doing some of the exercises mentioned in there if you have any trouble you can always ping me on twitter or just send out an email I'm always there to help thank you