Finally, the basic understanding of Node.js is understood, so its time to use a framework in it. Express is a web application framework designed for building web applications and APIs. It is also the common use case for Node.js.
Installing express on node is quite simple.
I just had to create a variable equal to requiring express from Node. Then I just called express to run it. The next issue I would run into is where is the file listening. If you have the file listening to a specific server it may mess things up when you switch it from test environment to the deployment server.
A method to overcome this problem is to create environment variables. Environment variables are global variables specific to the environment server our code is living in. Different servers can have different variable settings, and we can access those values in code.
HTTP method specifies the type of action the request wishes to make. GET, POST, DELETE, and others.
The method above gets an html file but a more common use case would be to get JSON files.
Another reason why Express is so commonly used is because of its middleware capabilities. Middleware is code that sits between two layers of the software. In the case of Express, sitting between the request and the response. This allows requests to be automated responded to when files are being requested from the server. HTML, CSS, and image files are ‘static’ files. Express.static is a middleware function that serves static files.<div class='sharedaddy sd-block sd-like jetpack-likes-widget-wrapper jetpack-likes-widget-unloaded' id='like-post-wrapper-155635758-468-5d077a918c1f5' data-src='https://widgets.wp.com/likes/#blog_id=155635758&post_id=468&origin=trilamanila.com&obj_id=155635758-468-5d077a918c1f5' data-name='like-post-frame-155635758-468-5d077a918c1f5'><h3 class="sd-title">Like this:</h3><div class='likes-widget-placeholder post-likes-widget-placeholder' style='height: 55px;'><span class='button'><span>Like</span></span> <span class="loading">Loading...</span></div><span class='sd-text-color'></span><a class='sd-link-color'></a></div>