I will be notified if you click this 😈

Shuvo - Oct 19 '21 - - Dev Community

Would you like to get notified when someone opens your dev.to article or reads your email? Yea that will be awesome. Okay then lets see how we can do that?

Lets talk about Images they are pretty cool right? Imagers are everywhere including in Articles and Emails.
So let see how image work.
In markdown you use images like this

![alt text](https://yoursite.com/some_image)
Enter fullscreen mode Exit fullscreen mode

Or in HTML you'd use the image tag

<img src="https://yoursite.com/some_image" alt="alt text" />
Enter fullscreen mode Exit fullscreen mode

and of course the markdown above is later compiled to HTML So lets focus on that.

So when a webpage have an image the browser will send an http request to the URL which is in the src of the image(https://yoursite.com/some_image in our case).
And then https://yoursite.com will send us and image which will be later shown to us in browser.
So the server-side code of https://yoursite.com/ could look something like this

app.get("/some_image", (req, res) => {
     res.sendFile('some_image.jpg')
})
Enter fullscreen mode Exit fullscreen mode

But the question is, is it that all we can do? Well its our code we can do whatever we want. So why not just notify our self that someone viewed this image?

app.get("/some_image", (req, res) => {
     notifyUser() //You can implement it the way you want
     res.sendFile('some_image.jpg')
})
Enter fullscreen mode Exit fullscreen mode

Now we will be notified whenever a user sees our image. That also means that if we use this image in our article/email we will know when a user opens it/reads it.

So if you're seeing this image that means ...
Meme image

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .