In this short story, the author's purpose is one that appears often in Hawthorne's writing - exposing the hypocrisy of Puritan society. You can read a good analysis of the story here on enotes at the link below.
From the beginning of the story, there is a sense of foreboding because it takes place at night. For some reason, Goodman Brown's wife, Faith, does not want him to leave on this particular night, and her husband replies:
"My love and my Faith," replied young Goodman Brown, "of all nights in the year, this one night must I tarry away from thee. My journey, as thou callest it, forth and back again, must needs be done 'twixt now and sunrise.
There is foreshadowing that something sinister is about to occur. As Goodman Brown proceeds on his journey, he encounters a mysterious individual who is the devil in disguise. The language describing the setting of the forest is eerie:
He had taken a dreary road, darkened by all the gloomiest trees of the forest, which barely stood aside to let the narrow path creep through, and closed immediately behind. It was all as lonely as could be; and there is this peculiarity in such a solitude, that the traveller knows not who may be concealed by the innumerable trunks and the thick boughs overhead; so that with lonely footsteps he may yet be passing through an unseen multitude
Goodman Brown then encounters the devil who at first, seems just like an ordinary old man, but Brown notices his staff:
But the only thing about him that could be fixed upon as remarkable was his staff, which bore the likeness of a great black snake, so curiously wrought that it might almost be seen to twist and wriggle itself like a living serpent. This, of course, must have been an ocular deception, assisted by the uncertain light.
Goodman Brown tries to tell himself that he is seeing things.
Other elements that evoke the terrible atmosphere are the darkness of the forest, Brown's reluctance to leave the path (symbolic for sin, leaving the path of righteousness), the mention of "an Indian behind every tree" (when the story was written, the settlers were still living near and being afraid of Native Americans in New England).
When the two travelers encounter Goody Cloyse, an old woman whom Goodman Brown recognizes as his Sunday School teacher, the references to witchcraft, devils, coven meetings and evil doings is revealed:
But--would your worship believe it?--my broomstick hath strangely disappeared, stolen, as I suspect, by that unhanged witch, Goody Cory, and that, too, when I was all anointed with the juice of smallage, and cinquefoil, and wolf's bane"
"Mingled with fine wheat and the fat of a new-born babe," said the shape of old Goodman Brown.
"Ah, your worship knows the recipe," cried the old lady, cackling aloud. "So, as I was saying, being all ready for the meeting, and no horse to ride on, I made up my mind to foot it; for they tell me there is a nice young man to be taken into communion to-night. But now your good worship will lend me your arm, and we shall be there in a twinkling."
You can read the story here on enotes and there is a modern English version. Go through the story and pick out other elements of language and setting that evoke a terrible atmosphere. Sin, confronted, is ugly, and it ruins Goodman Brown for the rest of his life. He never knows whether it was real or a dream, but it forces him to concentrate on the sin of his fellow man for the rest of his life.