Working with request headers in express.js

When receiving an http request from a client, that request will contain all kinds of headers that tell the server useful information about the request. The subject of headers in general can eat up a lot of time because there are a lot of them. However there are great resources such as at Mozilla as usual that outline what all the typical standard headers are when it comes to http requests. This is however a post on expressjs a tired yet true nodejs framework and how to work with incoming request headers.

So then in this post I will be quickly covering some examples of how to work with request headers in express.js with some help with the req.get method method, and the req.headers array that can be found in a request object.

Read More

The express.js body parser module, and basic full stack development.

Being able to parse a payload given to a node.js back end typically via a post request is a very common task when doing something with express.js. As such there is a built in way to quickly do this thanks to the body-parser module that is included with every express.js install (at least with the versions I have used thus far). In order to get into body parsing it is necessary to put together at least a basic full stack application. So in this post I will be giving a an example that will include both front and back end code. However this is a post mainly on req.body, and how to parse that using the body parser module so I will be mostly covering that.

Read More

Request objects in express.js

An request express object comes into play when using expressjs to help work with incoming http requests. The express request object that is one of four potential arguments that can be used when making an middleware function that that can be used when making application or router level middleware typically with a method like app.get, or app.use. The request object contains all kinds of useful properties and methods when it comes to working with incoming http requests. There are also of course response objects as well but, in this post I will be writing about some of the must know features of request objects when working with express.js.

Read More

Rendering with ejs in express.js

When rendering a template in express.js there are many options to choose from, however so far I seem to prefer Embedded javaScript or EJS for short, over other options such as pug. I have written a post on using the ejs module by itself in node.js as the package can be used by itself outside of express as a way to render html with ejs templates, and some data. However this post is more about using it in an express.js environment, as such I will be covering how to set up an express view folder using ejs as a template language.

Read More

Express static serving static files with express.js

In this post I will be writing about serving static files in a node.js environment using express.js. The process is pretty straight forward using an express.js built in middleware for doing so (express.static). The express static middleware can be used in conjunction with or as a replacement for a view engine. There are some additional options of interest as well thought so lets take a look.

Read More