Skip to main content

Serve-favicon third party middleware

 Hello!. Welcome to another moment with me again to learn and code on this platform. Today, I am going to be talking about how to add favicons on your web applications. Basic knowledge in node js and express js is needed to go through this tutorial.

I know some people might be wondering what a favicon is.

I think let me show you what it is, since a picture speaks a thousand times better than words. Have you ever noticed a little thumbnail image beside the title at the tab of a webpage ?

Serve-favicon third party middleware

Did you see that!. That’s a favicon. As you can see, the one above is for medium.com website and that of express website.

I mentioned earlier that serve-favicon is a third-party middleware, meaning it must be installed before usage.

To install this middleware or module, navigate to your project’s directory from a command prompt window and type the command;

npm install serve-favicon

Ensure you have a working and good internet connection. Wait for some time as npm downloads and installs this module in your local machine.

Also, this middleware makes use of the path module which handles the path to the image to be used as favicon.

Now lets look at its usage.

 server.js

Serve-favicon third party middleware

From the code above, note that;

- The favicon used here is an image (logo.ico) in the public folder located in the project directory. This was achieved using the path module.


Serve-favicon third party middleware
- This middleware faviocon () takes as parameter the path and maxAge paramter, though in this case we used just the path param. As you already know, the path provides the source of the image.
- The maxAge parameter simply extends the amount of time the image(icon) will be cached and used as favicon. By default, it is one year even when the parameter maxAge is not set.
- If you refresh your web page and it doesn’t work, then ensure you clear cache and try again or press ctrl + F5 on the web page.

OUTPUT

Serve-favicon third party middleware


It worked! Bravo!

Serve-favicon third party middleware

Thanks!

Comments

Popular posts from this blog

JavaScript Functions

  Hi there, and welcome to another exciting lesson on JavaScript. If this is your first time here, please do well to check out our previous lessons. In the previous lesson, we were discussing JavaScript math methods. It was very intuitive as we got to learn how to use the various math methods. To proceed, we shall be looking at JavaScript functions.  A function in JavaScript like in every other programming language could be defined as a block of code that is written to perform a particular task, and this function is usually invoked or called before it is being implemented. We have been talking about methods throughout the previous lessons right. Do you know that those methods are actually functions? Yes they are functions. You can now have an overview of the importance of functions in every programming language. How do we create a function in JS? To create a function, you follow the format function functionName(Argument) {//Block of code }. Some functions do have a return val...

JavaScript Math Methods

Hello everyone, and welcome to another exciting JavaScript lesson. In the last lessons you have been seeing other methods being used in JS (for example, the string methods). We shall go further into exploring other methods. This time, it’s going to be math methods. Do not move an inch because it’s going to be a very exciting. Before we look at what a math method is, let’s have an overview of math objects. A math object in JavaScript is a static built-in object that includes properties and methods used in performing mathematical tasks. Talking about math properties, they have the syntax Math.property . Some examples are Math.E that returns Euler’s number, Math.PI that returns PI, Math.LN2 that returns the natural logarithm of 2, and many others. The various JavaScript methods contained in the math object, thus, make mathematical operations easier and reduce effort as well as time in math-oriented programming. Some JS methods include abs( ), ceil( ), cos( ), sqrt( ), pow( ), log( ) ...

How to generate random numbers using NumP1

Hello. Welcome to another edition on this platform. For more better understanding, do checkout our YouTube channel to get the video tutorial. In this article of today, we are going to see how to generate random numbers using any of the following methods: Generating a random number Generating a random float and integer Generating random number arrays Generating random number from an array What is a random number? This is a number which cannot be predicted before its occurrence. This number might not different every time. Programmatically, they are two categories of random numbers:     Pseudo-Random numbers       True Random numbers. Just as programs which are written by programmers are a set of instructions, we must follow an algorithm to generate random numbers. Random numbers which are generated using an algorithm are called Pseudo-Random numbers. To generate a true random number, it is important to get the data from sources such as the keyboards, mou...