Hundreds of thousands of illegal aliens, many penniless and hungry, are fleeing Nigeria by truck, boat, aircraft and on foot and are streaming into other West African countries after the Lagos government ordered that all undocumented foreigners must be out of the country by today.

Nigeria, suffering from serious unemployment in an economic downturn caused by the world's oil glut, announced the expulsion order unexpectedly Jan. 17 after blaming the aliens for bloody religious riots that erupted in the northern section of the country last fall. Actual movement was slow until last weekend because Ghana refused until Saturday to open its borders to its returning nationals, and other countries were hesitant to take the Ghanaians in, according to news services, radio broadcasts and State Department officials.

Nigeria has not said how many people are involved in the exodus, but State Department officials said the number of illegal aliens in the country could run between 2 million and 3 million. Most of the aliens are West Africans, and about half are estimated to be from Ghana.

Nigeria has said that after today's deadline, "government agents will inspect commercial and industrial sites, as well as households, to identify defaulting aliens" and will "repatriate" them. Thousands of people massed at the port in Lagos waiting for boats and others were caught in Benin and Togo as they waited to cross into Ghana. About 1,000 people a day are reportedly leaving on special flights to Ghana, but most of the evacuees are too poor to afford the $150 fare.

Information from Nigeria about the exodus has been scarce since regular communications to the country were broken by a fire in the telecommunications building early last week, and Nigeria has been hesitant to allow western reporters to interview the foreigners. But U.S. officials said there have been few reports of violence caused by the expulsion order.

Because Ghana closed its land border in September to halt smuggling, many of the aliens spent last week at the port near Lagos waiting for promised boats from Ghana. Nigerian officials estimated that the crowd grew to more than 100,000 people. News services reported that there were no sanitation facilities or shelter in the area for the Ghanaians and only one refugee boat--carrying 6,000 people--is believed to have left Lagos for Accra in the past two weeks. Fighting was reported among many of the desperate refugees seeking space on the boat.

Nigeria, saying the port traffic was being disrupted by the massive congregation there, last week ordered the foreigners to leave the port or face "ruthless" reprisals. But most of the aliens refused to budge, and Nigeria did not send in police, news services said.

Once Ghana announced that its border would be open 12 hours a day at Afloa, many of those at the port made hurried arrangements to go home by land. Ghanaians crowded around Nigerian truck drivers offering to take them home along the coastal road running from Nigeria through Benin and Togo to Ghana for an average fee of $60. Many people were reported to be selling their belongings at the port yesterday to raise money for the land trip.

By yesterday afternoon, Reuter reported from Nigeria that more than 100,000--many of whom were part of a double line of vehicles stretching bumper-to-bumper for two miles from the border--had moved across the frontier to Benin on the way to Ghana. The news agency estimated that 400,000 people had passed through the checkpoint at Seme, the major crossing point between Benin and Nigeria, since the eviction order was issued by the minister of internal affairs, Alhaji Ali Baba.

The government of Togo has requisitioned several dozen heavy trucks to shuttle the travelers the 30 miles from the frontier with Benin to Aflao, Agence France-Presse reported. The news agency reported a traffic jam at Aflao, however, because of a lack of vehicles to pick up the returning people.

Many of the Ghanaians are camping along the road in Benin awaiting their turn to move into Togo and on to their homes. Immigration officials in Benin, however, warned that they cannot provide enough shelter, food, water, medical care or security for the refugees, and the Red Cross there said it is not equipped to handle the load, AFP reported.

Ghana, Togo and Benin have set up emergency reception centers for the evacuees whose trip is made more difficult by shortages of water and sweltering heat. The League of Red Cross Societies, an aid organization based in Geneva, is scheduled to airlift Tuesday 500 tents, 10,000 blankets and thousands of buckets, spokesman Jurg Vittani told United Press International.

Some of the hundreds of Ghanaians crossing the border into Ghana on Saturday told AFP that they had spent more than 10 days in unhygienic conditions waiting along the roads to get home, with nothing to eat or drink.

Refugees, mostly men between 20 and 30, fought over bread thrown to them by a crowd as they passed through Lome, Togo, AFP reported.

State Department officials said the United States is preparing to offer aid in the refugee problem, but so far no country has made a formal request. U.N. and other international organizations are known to be preparing to aid the refugees.

One U.S. official said most of the refugees were known to be employed in the construction industry and many others were employed as security guards. Some were also middle-management officials in banking and industrial concerns, he added.

Many of the foreigners are believed to have entered the country under an agreement of the Economic Community of West African States, which allows citizens from member countries to enter Nigeria without visas for 90 days.

Although Nigeria has consistently blamed foreigners for the religious fighting last fall, the expulsion is believed to have stemmed from broader economic problems, a State Department official reported. Nigeria, which enjoyed a buoyant economy during the oil boom of the 1970s, has been forced to cut back on its economic development plans as the global oil glut dramatically reduced its sales. Its oil revenues dropped more than 50 percent during the past two years, and at the end of last year Nigeria faced a short-term debt of $5 billion.

Despite stringent austerity measures, Nigeria's financial position could be jeopardized further by a possible fall in world oil prices.

The government ordered the expulsions apparently because it was getting nervous about discontent over the economic downturn and rising unemployment, a State Department official said. The order has been supported by a "chorus of seeming unanimity in the Nigerian press," he added.