Need: something people would be much better off if they had (or even, will struggle to survive if they don’t have). Example: fresh vegetables.
Demand: something that people are actively looking for, and will pay money to get. Example: McDonald’s.
If you want to write a book that sells (or create any other successful product), figuring out if there’s a demand is more important than figuring out if there’s a need.
Lots of security and software engineering books deliver on a need. But is there a demand? Do people really want to buy books on those things?
Valuable, ethical products and books deliver on both. How can you present your useful, important book in such a way that people will want it?