Jokes aside - it can be tough. I recommend if you have not already done a reverse time based analysis, you do so. If you're wondering this at 40, what about 60? Think about where you want to be and how you will be perceived going forward, combined. That will help guide some of what you do with an eye towards your longevity.
Anyway, at 40 there is a high expectation to support and mentor - first and foremost. Help people see their bugs, secondarily improve their methods, and thirdly listen to their ideas to help you paint their strategy (rather than your own interpretations and strategies which may be dated).
Second, younger people may see you as the older guy with the stodgy ideas. Avoid fighting with them on that front, even though your role may ask for that. You are in a losing battle often with that up front, unless your upper management really supports your ideas. And even then be careful to be respectful - you may change your mind after some research and find you support their initially backward sounding idea.
I recommend supporting and contributing to your coworkers projects to highlight your solution methods, and show them you care. You probably have a lot of good to offer, and this will defray any potential hostility.
I am not sure if you are Indian or person of Indian heritage, and if you are working in India or abroad, but within Indian context, being a developer at 30+ is not seen favorably. I tried changing jobs at 34 in 2014 with 12 years experience, and was constantly offered a "leadership" position when all I wanted was to be a lead developer with freedom, basically same as my last job. I didn't take any of the offers, also because I wanted to start my own company. Things didn't workout and now I am looking for a job again, at 38. This time I have wised up and won't insist on engineering position. I am a realist, and have made my peace with it. I am preparing myself mentally to do something that I have always despised - filling excel sheets with colored cells.
---
Further, personally, because I will indeed start my company once my financial condition improves, and I can do all the engineering I ever want with all the freedom I always wanted, I don't much care for the nature of the task I do as an employee elsewhere. I have no intentions of making a career working for someone else.
That said, I have an inkling that I might have it harder this time since I was unemployed chasing a dream for four years, and I am not sure how Indian companies (well, Indian outposts of Amerieuro companies) consider it. The weak link is of course the mind set of Indians who do the interviews, who would be mostly my age, and I don't know if the hype around startups has made them "open minded" or created further loathing of people treading that path because, let's face it, most Indian startups are copycats and hardly innovative, and its quite challenging to appreciate efforts of people who whip out yet another clone and pose as if they are innovators of cutting edge technology, and its quite likely that startup attempters will be prejudged negatively.
Somebody that goes to the gym infrequently and keeps their health above average will probably still be like their 30's, maybe 25(?)'s.
It is not so bad. I think by 60's it can get nasty, but by them, you will be stuck with some legacy crap nobody can understand. But there might be 60 year olds doing frontend in vue, why not. You chose if you want to age.
Seriously though - at 20 years experience you probably have a lot you could mentor and nurture in other people?
Not everyone can be managers true but where do you see yourself in another 10 years?
Unless you are doing something "old school" like Cobalt, Fortran or something equally as esoteric by todays standard then do you have the energy to keep maintaining your skill set with the latest tools?
More likely they started out working in C++, C, Java, etc. Back then more developers worked on desktop apps than web. C# first came out in 2000 (18 years ago), Python is 28 years old, Ruby 23 years old, so chances are their knowledge and experience is fairly modern apart from the current trendy web frameworks.
Lots of C++ & Java in those days. Mostly C++.
JK
But seriously, as I was getting towards 40 I heard that a lot.
I still like to code more than manage.
Trying to hire a COO now, so I can manage less and build more.
I'm just slightly kidding.