Express end response method

The express end response method is one of several ways to go about ending an incoming http request from a client system. The express end method is used for situations in which the request is to just simply be put to an end without sending any data to the client, or preforming any kinds of other action such as redirection to another path.

It is true that the method can be used to send data in the form of a string or buffer to the client, but another response method should be used such as res.send, or res.json that are also at hand in a response object.

Read More

Express response objects

An express response object is one of four possible arguments that is passed to an express middleware function. Expressjs has to do with the use of middleware that does something with incoming http requests. So request objects have to do with the incoming http request from a client system, and response objects have to do with the response to that system. The other two arguments in an middleware method have to do with error handling, and passing along control to another middleware method. However in this post I will be focusing on just response objects today.

Read More

Express redirect response object method

An express redirect is one of several options when it comes to responding to an incoming http request when working out one or more middleware functions for a path, or pattern. Often a response will involve just sending some json, text, or html, but in some cases a redirect to another path might be called for as a way to respond to a request. For example maybe I have a path that will serve a 404 response page, a user can go directly to such a path, but more often that not they will get there because the resource they where looking for was not there, and I can send them there by way of a res.redirect call in a middleware function that they will only get to if that is the case.

In express redirects can be done with the res.redirect response method, for the most part just the url of the resource to redirect to is all that needs to be passed, but some times it is not that simple when it comes to the response status codes. So in this post I will be writing about all things express redirect related that I come across that are note worthy.

Read More

Express view

An express view folder contains template files that are use for server side rendering. It can be used in place of, or in conjunction with other assets that can be served via express.static when it comes to just simple static hosting of files. Using express static to host a public html folder might work okay, and in some situations in might just be what needs to happen. However by going with a template language, and using a render engine, server side rendering of html can be preformed using nodejs an express.

In order to use a view folder there must be a template engine to use. I tend to prefer ejs, but there are many other options such as pug. So this post will be centered around setting up the beginnings of an express view folder, and maybe I will get into some more advanced topics when it comes to creating a client system for a project.

Read More

Express Type

The express type response object method can be used to quickly set the Content-Type response header to a desired mime type, and in most cases it will work fine, but it might still be better to use the res.set method as a way to set Content-Type to make sure that the correct mime type is set for the content that is being sent to the browser. Never the less this will be a quick post on the express type convenience method as well as some related topics with Content-Type and response headers.

Read More