DEV Community

Cover image for Embracing the Future: Meteor 3 with Node v20 and Express
Denilson for Meteor Software

Posted on • Updated on

Embracing the Future: Meteor 3 with Node v20 and Express

Meteor, a powerful full-stack JavaScript platform, has undergone a significant transformation with its latest update, Meteor 3. This upgrade not only modernizes the framework but also enhances its capabilities by integrating the latest Node.js features, including version 20 LTS, and moving from Fibers to native async/await syntax. Let’s dive into how these changes benefit the Meteor ecosystem.

Table of contents:

Launch Week - Day 1

We're excited to launch the new Meteor 3.0 Docs and Migration Guide today!

Check out the new V3 Docs at (https://v3-docs.meteor.com/), which focuses solely on Meteor 3.0 and steps away from backward compatibility. While much remains familiar from Meteor 2.x, there are key differences, and these new docs are here for 3.0 only. If you’re still on version 2, your go-to resource remains https://docs.meteor.com. As we roll out the official version 3, it will take the lead on our website, transitioning the current documentation to v2-docs.meteor.com.

The Migration Guide (https://v3-migration-docs.meteor.com/) is here to help those of you on Meteor 2.x seamlessly transition to 3.0. It highlights the changes, answers your frequent questions, and guides you through the transition, including modified and removed functions. Plus, we’ve included helpful links to community resources!

We’re super excited to see your projects take advantage of Meteor 3.0! Go ahead, explore the new resources, and let us know your thoughts. Your feedback is crucial - share your suggestions, report issues, and contribute. Let's make Meteor 3.0 the best version yet!

And while we're here, let's explore Meteor 3.0 more.

The Shift from Fibers to Async/Await

For years, Meteor relied on Fibers to simplify asynchronous code, making it look and behave synchronously. This approach was instrumental in avoiding callback hell and enhancing code readability. However, Fibers became a limiting factor as it was not compatible with newer versions of Node.js, particularly from version 16 onwards.

Removing Fibers was a critical step in bringing Meteor up to date with the most current Node.js stack. This transition allows Meteor to leverage all the new features that Node v20 provides. Async/await, a feature now fully supported in Meteor 3, is a prime example.

Example of Async/Await in Meteor:

Meteor.methods({
  async getUserData(userId) {
    try {
      const user = await UsersCollection.findOneAsync({ _id: userId });
      return user;
    } catch (error) {
      throw new Meteor.Error('user-fetch-failed', 'Could not retrieve user data');
    }
  }
});
Enter fullscreen mode Exit fullscreen mode

This example demonstrates how you can fetch user data asynchronously. Using async/await ensures the code is clean and easy to read, and error handling is straightforward.

Meteor 3 and Node v20: A Powerful Combination

Node v20 brings several enhancements that Meteor 3 utilizes to improve performance and developer experience. These include Top-Level Await and Timers Promises API!

Top-Level Await

Allows using the await keyword outside of async functions within modules, simplifying the initialization of applications.

// At the top level in your Meteor app's server-side code
const settings = await SettingsCollection.findOneAsync({ key: 'app-config' });
Meteor.startup(() => {
  configureApp(settings);
});
Enter fullscreen mode Exit fullscreen mode

This feature allows developers to perform asynchronous operations before the application fully starts, ensuring that necessary configurations are in place.

Stable Timers Promises API

Provides a promise-based alternative to traditional timer functions like setTimeout and setInterval, enhancing the way delays and periodic tasks are handled in a non-blocking manner.

import { setTimeout } from 'timers/promises';

Meteor.methods({
  async delayedGreeting(name) {
    // Wait for 2 seconds before continuing
    await setTimeout(2000);

    // Process after the delay
    return `Hello, ${name}!`;
  }
});

Enter fullscreen mode Exit fullscreen mode

These are only two examples of how Meteor 3 takes advantage of the features Node 20 offers. Another great addition to Meteor is the integration with Express.

Integrating Express into Meteor

Image description

The adoption of Express in Meteor 3 opens up new possibilities for developers, especially when building RESTful APIs or serving static files. Express is a minimal and flexible Node.js web application framework that provides a robust set of features for web and mobile applications.

Here is an example of using the WebApp.handlers as your express instance as you typically would:

import { LinksCollection } from "/imports/api/links";
import { WebApp } from "meteor/webapp";

WebApp.handlers.get("/all-links", async (req, res) => {
  const links = await LinksCollection.find().fetchAsync();
  res.json(links);
});

// other code ...
Enter fullscreen mode Exit fullscreen mode

In this example, express is used to define a simple API endpoint that returns data from a Meteor collection. This setup shows how seamlessly Express can integrate into the Meteor ecosystem, providing familiar tools for those accustomed to traditional Node.js development.

You can read more about Meteor with Express here!

Preparing for the Official Release: Understanding Meteor 3's Current State

As we approach the official launch of Meteor 3, it's important to recognize that we're currently in our Release Candidate (RC) phase. This is a critical moment where we're very close to the full release, and we've already undergone several reviews to refine and enhance the framework.

This is the current status of versions for Meteor 3:

Latest version: 3.0-rc.2
Node.js version: 20.12.2 LTS
NPM version: 10.5.0

Recent Updates and How to Use Meteor 3 Now

Image description

Meteor 3 has undergone significant updates in its RC versions, focusing on fixing key issues to ensure stability and performance. You can check all the work we have done up to now in our 3.0 Milestone on GitHub or in the Roadmap post we have in our forums where we update the community periodically about our progress.

If you're eager to start using Meteor 3 right away, you can install the current version using the following command:

npx meteor@rc
Enter fullscreen mode Exit fullscreen mode

For those looking to upgrade from Meteor 2 to Meteor 3, the process is straightforward. You can update your project by running the following:

meteor update --release 3.0-rc.2
meteor reset  # resets local DB and project to a fresh state
Enter fullscreen mode Exit fullscreen mode

But it'll be this simple only if you are already in the current 2.16 version and have prepared your app with the new async API.

If you are not in version 2.16 yet, make sure to follow the migration guides from your current version up to Meteor 2.16.

If you're already in version 2.16 but still haven't prepared your app, you can follow our 3.0 Migration Guide.

Community Feedback and Next Steps

Your feedback is invaluable as we finalize Meteor 3 for its official release. We plan to issue new release candidates every two weeks, incorporating community input to refine and improve the framework. This iterative process is essential for ensuring that Meteor 3 meets our community's needs and expectations.

This means your feedback is extremely important. Create new apps, update existing ones, and provide us with your findings. This way it will be faster to find and solve edge-case issues and release the final version sooner.

Conclusion

The transition to Meteor 3 with Node v20 and Express is a significant leap forward for the Meteor community. This upgrade ensures that Meteor remains a competitive and modern framework capable of handling the needs of today's web and mobile applications. By embracing these changes, developers can enjoy improved performance, enhanced scalability, and a more intuitive coding experience.

For a deeper dive into implementing these features and more, visit the official Meteor documentation and our Migration Guide and explore the rich ecosystem that Meteor continues to offer. As always, you can be part of our wonderful community in our Forums and Slack.

We also can't finish this without thanking everybody who helped the Meteor team throughout this process. Thanks to everybody in our forums and Slack for feedback and suggestions, but also thanks to everybody who directly contributed with PRs and reviews. This couldn't be done without you ❤️

@denihs
@Grubba27
@nachocodoner
@fredmaiaarantes
@vit0rr
@filipenevola
@zodern
@radekmie
@StorytellerCZ
@gunnartorfis
@xet7
@harryadel
@CLAassistant
@simonwebs
@TylerThompson
@rodrigok
@zarvox
@srsgores
@tassoevan
@Torgen
@MarcosSpessatto
@vincentcarpentier
@ggazzo
@StevenMia
@acemtp

Top comments (8)

Collapse
 
guncebektas profile image
BEKTAŞ

Great news 👍🏼 really happy to see these days. Congratulations 🎉🎉

Collapse
 
vialec75 profile image
Vianney Lecroart

go meteor go

Collapse
 
theteacherjoao profile image
João Corrêa

Nice and easy read, looking forward to testing, experimenting and implementing things using Meteor 3.0.
A big shout out to the Meteor Team!

Collapse
 
vedmalex profile image
Vedanta-krit das (Alex Vedmedenko)

Wow!!!
Meteor is Live! now!!!

Collapse
 
tim_heckel_651d04aee0e3d3 profile image
Tim Heckel

Huge props! This was so long in the making, and I sincerely appreciate all the effort in extracting fibers a reality. Huge accomplishment.

Collapse
 
__f763ae43e268514394bd2 profile image
Cai

Great! Thanks very much to all the meteor developers!
It's bettor if there are some simple examples of meteor v3 so that the fresh coder can quickly understand how to use meteor V3.

Collapse
 
fredmaiaarantes profile image
Frederico Maia

Thanks, Cai! Please check out SimpleTasks here: github.com/fredmaiaarantes/simplet....
We'll share more examples soon.

Collapse
 
poetsmeniet profile image
Thomas Wink

Amazing. The wait was long, but certainly worth it!