The S&P 500 and the Nasdaq Composite have spent the better part of the past year in a bear market, weighed down by widespread fear about the economy. But smart investors know that a bear market is a buying opportunity, simply because indiscriminate downturns tend to drag the good stocks down along with the bad.

Eventually, the next bull market will wipe away many of these losses, sending both indexes to new highs. When that happens, the good stocks -- the businesses that hardened like diamonds under the pressure of a difficult economic climate -- will likely rebound in a spectacular way, creating wealth for patient shareholders.

With that in mind, here is one stock to buy now and one stock to avoid for the foreseeable future.

Cloudflare: A growth stock worth buying

Cloudflare (NET -3.34%) operates a global network that improves the performance and security of applications and IT infrastructure while eliminating the cost and complexity of maintaining network hardware. Its portfolio also includes developer tools and storage services that allow businesses to build performant software and websites directly on its network.

Through massive scale and relentless innovation, Cloudflare distinguished itself as the fastest cloud provider on the planet. Its network can deliver content to 95% of internet users worldwide within 50 milliseconds, and the promise of performant applications and infrastructure has fueled strong demand. Cloudflare powers more than 20% of the internet, and it ranks as the leader in content delivery network software. But the company is also gaining momentum in other areas. For instance, Forrester Research recently named Cloudflare a leader in edge development tools.

Not surprisingly, the company consistently reports impressive financial results. Third-quarter revenue climbed 47% to $254 million, and Cloudflare achieved a record operating profit of $15 million. But investors have good reason to believe that momentum will continue.

Looking ahead, zero trust security is an exciting growth opportunity. Cloudflare debuted an email security product earlier this year, building on the recent launch of Cloudflare One, a secure access service edge (SASE) product. SASE platforms are the future of networking and security, as they allow users to quickly and safely access corporate resources and the open internet from any device or location. In fact, IT research company Gartner says 80% of enterprises will adopt SASE platforms by 2025, up from 20% in 2021.

To capitalize on that tailwind, Cloudflare announced the Cloudflare One Partner Program earlier this year. That program expands its go-to-market strategy by equipping IT consultancies, managed service providers, and other partners to drive the adoption of Cloudflare One among their own customers.

Currently, Cloudflare estimates its total addressable market at $115 billion in 2022, but management expects that figure to grow at 8% annually to reach $135 billion by 2024. And with shares trading at 16.8 times sales, an absolute bargain compared to the three-year average of 41.8 times, this growth stock is a screaming buy.

Twilio: A growth stock worth avoiding

Twilio (TWLO -0.73%) operates a cloud communications platform comprising a range of application programming interfaces, or APIs (i.e. code that allows two software programs to interact). Twilio APIs make it easy for developers to embed communications like text, voice, and video into their applications. Twilio also provides higher-level APIs that blend individual communication channels into more complete products. For instance, Twilio Flex is a programmable contact center and Twilio Engage is a data-driven marketing platform.

Twilio acquired several companies over the years, including email API platform SendGrid in 2019, customer data platform Segment in 2020, and toll-free messaging platform Zipwhip in 2021. By blending customer data and communications, Twilio built a customer engagement platform -- a suite of developer tools capable of creating personalized customer experiences across any digital channel.

That ambitious vision paid off in some ways. Twilio is the clear leader in the communications platform as a service (CPaaS) market, but it achieved that success by burning a tremendous amount of cash, and the situation is only getting worse. Twilio reported negative free cash flow (FCF) of $147 million in the third quarter, down from a negative FCF of $82 million in the same period last year.

Worse yet, CEO Jeff Lawson made the following comment in the first quarter: "We remain confident that we will deliver 30%-plus annual organic revenue growth through 2024." But Twilio pulled that forecast in the third quarter, citing the challenging macroeconomic environment, and its fourth-quarter guidance calls for 18% to 19% organic revenue growth. That is a big deviation from the medium-term target Lawson confirmed just two quarters earlier.

In a nutshell, Twilio enjoys a strong position in an $80 billion market, but the company is burning cash quickly and management seems to have limited visibility. For that reason, investors should avoid this stock until Twilio can turn the corner on profitability -- and I say that as a shareholder. To clarify, I am not suggesting that current shareholders unload the stock, at least not yet. But if the situation continues to deteriorate in the coming quarters, I may decide it's time to sell.