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

Introduction to flask

Hello. Welcome to another session on this platform. If you are new here, please do checkout our previous articles on python programming language and stay excited on this session because we are entering into one of python’s web-based application called flask. In this article, we are going to see the following What is flask Prequistes Installation of flask in python Some of flask template engine. What is flask? Flask is one of python-based framework which is used to create web applications. Flight is a very light web framework. During installation, flask comes with pre-installed modules and functions which are used to backup your own web applications. Flask is very easy to understand and perfect go-to for beginners and with flask, a web server can run in less than 3 lines of code. Prequistes Before learning flask, we recommend the reader to have a basic mastery of python concepts. Installation of flask  Before installing flask, we have to checked if python has been installed or. If n...

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...

Introduction to Django

Hello. Welcome to another session on this platform. If you are new here, please do checkout our previous articles on python programming language and stay excited on this session. we are entering into one of python’s application called Django. In this article, we are going to discuss the following: What is Django Why must we use Django  A brief history of Django Installation of Django Popularity of Django What is Django? Python has so many framework application and Django happen to be one of them. Being a python-based-framework, it is used to quickly create web applications.  When building websites, django provides similar ready-made components to handle user authentication, forms, a way to upload components. Why use django? Django is very fast. It takes applications from concept to applications very quickly Django has thousand available packages in it when it is installed. With django, we can launch web applications is a matter of hours. Django is a highly is secured and helps...