It can sometimes function as an adjective, describing something that is nightmarish, but this usage is less common.
Here are some examples:
Noun: "I had a nightmare last night."
Adjective: "The situation was a nightmare."
It's important to consider the context to determine the part of speech.