Well, the easiest way is to level up until your character has reached level 40!
Okay, more seriously, I take it you're talking about how to reach level 40 with your character in the original Neverwinter Nights campaign?
If so, there's unfortunately no way to reach the level cap by simply playing the campaign(s).
Even the Hordes Of The Underdark expansion will get your char "only" up to level ~27.
If you're looking for any options to "farm xp" or something, it can't be done, as far as I know.
The only way would be to export your char and play a fan-created module that would get them to level 40*. Or you could use the console to artificially give your char more XP.
Of course, using such a char afterwards to play the original campaign would be pointless, since it would be way too powerful to make a playthrough even remotely entertaining.
* It's been some time since I played any, so unfortunately I can't give you any recommendations . Maybe someone else can chime in with some suggestions?