The flippant (but true) answer is with great difficulty and confusion.
But night attacks were occasionally staged, and could confer desirable benefits to the attacker by denying the enemy its air and armoured support, and stifling its gunnery/artillery. Typically such actions would rely on some form of illumination, be it moonlight, flares, or, in cloudy conditions searchlights could be bounced-off the clouds to create artificial moonlight. Heavy automatic weapons firing tracers (typically AA guns) could 'mark' an axis of advance making direction-finding significantly easier (and conversely, enemy tracer could be used to locate strong-points); excellent recon and preparation were essential to success - but however well-prepared one was, the nature of night-fighting inevitably devolved into a close-quarters brawl in which the grenade and bayonet trumped the gun. Thus, only the most well-drilled, well-led and courageous troops could hope for much success in such endeavors.
The New Zealand Division in North Africa was well-known for its night-fighting prowess - the desert was notoriously unforgiving for day-attacks by infantry due to its coverless terrain, but at night determined infantry came into its own and could be virtually unstoppable when fighting moved into cut-throat range. NZ soldiers were often advised not to fire their weapons as the flash gave away their position for negligible effect - closing on the enemy in virtual silence and sticking him with a bayonet was viewed as more effective. Riflemen became spearmen, fearsome defensive positions rather easily overcome with massed grenade-chucking. The unforgiving nature of the combat is exemplified by this quote from a lt. Marsden from the NZ 28th 'Maori' Battalion, when the NZ Division was encircled by German armoured divisions at Minqar Qaim:
"I can still see Lt Hupa Hamiora out in front of B Coy prancing, leaping and yelling as he led that famous haka Ka mate! Ka mate! No opposition was met by A Coy. We passed clean through the enemy defences (not manned), arty and troop carrying vehicles. The drivers of these were in bed either on or under their vehicles.
When there was no more opposition the red, white, green success signal was shot into the dusty sky and the brigade sorted itself out and re-formed. There were no prisoners to worry about and the men with reddened bayonets cleaned them in the sand while waiting the arrival of transport. A watchful eye was kept on the rear and flank in case of counter-attack, but the first battalion of Rifle Regiment 104 had been practically annihilated by 19 and 20 Battalions and the few survivors were heading due north as fast as their trucks could carry them."
http://nzetc.victoria.ac.nz/tm/scholarly/tei-WH2Maor-c7.html
The account is somewhat sanitary, but not at all - the defenders were caught unawares by the silent assault and 'practically annihilated' with 'no prisoners'. A more evocative account from the official history of the campaign follows:
"As soon as the Maoris reached their start line, 4 Brigade advanced. Probably definite orders to move were received by the companies poised on their lines. No one remembers them. The start seemed to be automatic, as if a familiar spirit had whispered that there was a rendezvous to keep and it was time to be on the way. With bayoneted rifles at the high port and Bren and tommy guns ready for action, the brigade stepped forward. An occasional rattle of equipment, an occasional slither over an outcrop of rock, sounded above the muffled tread of heavy boots in the sand and dust. Each man was aware of the presence of his neighbour and of the march of a host.
A hundred yards passed, then two hundred; now five hundred and then a thousand yards were gone. The slit trenches and the defence positions which had spelt security during the day seemed distant in the rear. The brigade was in the open, naked and exposed. The ‘point of no return’ was passed. Whatever happened, the brigade must go forward. There was now no alternative.
Then the enemy sprang to life. A few odd shots swelled rapidly into a cacophony of fire from rifles, automatics of all types, and anti-tank guns. Lines of tracer bullets crossed and recrossed with the appearance of a perfect fire pattern. Apparently the Germans had been waiting. It seemed impossible for any troops to get among the enemy without suffering heavy casualties. What would happen? In the face of such a blaze of fire would the brigade check? Would it falter? There was only one chance. Close with the enemy as fast as possible.
Fourth Brigade did not falter. To quote from Lieutenant-Colonel Burrows' report, ‘a most amazing and thrilling thing happened. To a man the whole brigade charged forward. No orders were given; no urging forward by officers and non-commissioned officers. With shouting, cheering and war cries every man broke into a run as if he knew exactly what was expected of him.'
The shouting and cheering were more of a frenzied yell. The pent-up emotions of the last minutes on the assembly line and of the steady march were freed. The yell was heard above the din of the fire. It carried 4 Brigade as on a wave into the defences. With a few yards to go, some men checked as if to return the enemy's fire and beat it down. What was their purpose, no one knows precisely, for check and sweeping on to close with bayonet, bomb and bullet were almost simultaneous ... Using bayonets, rifles, tommy guns, Brens fired from the hip and the newly-issued bakelite grenade, the two battalions penetrated into the centre of the close-parked laager. Here, for a few minutes, there was the ‘impassioned drama’ of war. No chances could be taken. Kill or be killed. The bayonet was used with terrifying effect. The German slumped in the corner of a trench or lying on the ground might be shamming. He might fire a shot or throw a grenade when backs were turned. A thrust or a bullet eliminated the risk.
In the slit trenches, most of the Germans had their boots off. Some were undressed. While some Germans attempted to surrender and some to make off by foot and in trucks, others fought hard. Machine-gunners who used the light of burning trucks or of deliberately lit petrol fires to help their aim were dealt with by the simple process of assault from all points except on the line of fire. Truck drivers used wheeled and half-tracked vehicles as tanks in efforts to overrun the attackers. Some got away, but most fell victim to bullets and bombs, including the sticky grenade.
The flashes of explosions, the blaze of burning vehicles, the smoke, dust and the yells and screams made an inferno through which 19 and 20 Battalions fought their way to the far side of the laager. They had punched the required hole. On the eastern side of the wadi, the companies and battalions reformed while the transport came up in response to the success signal. As the advance had been drawn off its axis by the greater resistance on the left, the majority of the troops were some distance to the north of the embussing point. Spasmodic fire caused a number of casualties while the troops were marching to the transport and in embussing, but the now calmer troops quickly got into the trucks and the whole brigade moved off in night formation to the east."
http://nzetc.victoria.ac.nz/tm/scholarly/tei-WH2Egyp-c12.html
I hope that gives an idea of WWII night-fighting as a kind of devolution in combat to a more savage era - 'knifework', so to say; but also a potentially highly effective means of evening the odds for an outgunned combatant - but it took a lot of mettle. A contrast might be the inexperienced German infantry divisions in the opening assault of the Ardennes offensive, who suffered severe casualties and achieved little genuine success.