![]() Once the server is created, you tell it to start listening for requests on a particular port – in our case we used 3939 – when you launch the program. You will typically pass a ServerRequest and a ServerResponse objects to the function. The createServer function takes only one argument, a function that will be called whenever somebody makes a connection to your server. The require function includes this function and we created a variable of http to refer to it. Node.js provides a lot of powerful functionality out of the box, and as we can see in the first line of the previous code, you can use one of the built-in modules – the http module, which allows your app as a web server. At the moment it only has one route and you can’t really do anything else with it, but from this point on we can scale it a bit more. ![]() Amazing lightweight webserver using node.jsĪs you can see we’ve created a pretty cool a web server in just 9 lines of code! Obviously it doesn’t pack all the features of Apache etc, but it still is a handy little web server.
0 Comments
Leave a Reply. |