The stock market has been on a downhill slide since the beginning of the year, and if you're feeling nervous about investing right now, you're not alone.

It can be an unsettling time to invest, and when stock prices are plunging, it may even feel downright dangerous. But the market is safer than it might seem, and Warren Buffett has some wise words for how to handle these types of downturns.

Should you keep investing right now?

On the surface, now may seem like the worst time to buy stocks. Millions of investors have watched their portfolios plummet in value, and the last thing you may want to do is throw more money into the market.

However, with the right strategy, now can actually be an incredibly profitable investing opportunity.

During a market downturn, stock prices are often much lower. Even the highest-priced stocks are heavily discounted right now, with some of them down 40%, 50%, 60%, or more. If you're looking for a chance to buy high-quality investments for a bargain, now is a fantastic time to invest.

Warren Buffett's advice for surviving a downturn

In 2008 -- at the height of the Great Recession -- the Berkshire Hathaway (BRK.A -1.10%) (BRK.B -0.84%) CEO penned an Opinion piece for The New York Times. In it, he explained why he was continuing to invest in the middle of one of the worst economic downturns in history.

"A simple rule dictates my buying," Buffett wrote. "Be fearful when others are greedy, and be greedy when others are fearful. And most certainly, fear is now widespread, gripping even seasoned investors."

He went on to explain that "bad news is an investor's best friend. It lets you buy a slice of America's future at a marked-down price." In other words, when the market is tumbling and many investors are worried about the future, that is one of your best chances to buy.

That said, it's still important to be selective about where you invest. In Berkshire Hathaway's 2021 letter to shareholders, Buffett explained that he and business partner Charlie Munger are business-pickers, not stock-pickers.

"[W]e own stocks based upon our expectations about their long-term business performance," he wrote, "and not because we view them as vehicles for timely market moves." Not all stocks will survive a market downturn, but by choosing the right companies, you're far more likely to see long-term investing success.

Investing now could lead to lucrative returns later

Investing in the stock market is playing the long game. That means it doesn't necessarily matter what happens in the coming days, weeks, or months. What really matters is how the market performs over years and decades.

Historically, the stock market has a fantastic long-term record. In fact, despite multiple major crashes, bear markets, and recessions, the S&P 500 is up by more than 900% since 1990.

Investing during the slumps can also set you up for significant returns when the market eventually recovers. For example, if you had invested in an S&P 500 tracking index in March 2009 (at the lowest point of the Great Recession), you would have seen returns of nearly 70% over the following year alone.

Chart showing large rise in the S&P 500 between early 2009 and early 2010.

^SPX data by YCharts

If you're nervous about the stock market right now, that's OK. And if cash is tight or you can't afford to leave your money in the market for at least a few years, it may be better to avoid investing for the time being.

However, despite volatility, the stock market remains one of the most effective wealth-building machines. It's not always easy to invest, but if you can swing it, investing in strong stocks from healthy companies can help you generate wealth that lasts a lifetime.