Home >Web Front-end >JS Tutorial >A brief discussion on how to run Node.js locally in the browser

A brief discussion on how to run Node.js locally in the browser

青灯夜游
青灯夜游forward
2021-05-25 10:06:102635browse

This article will introduce you to the method of running Node.js locally in the browser. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

A brief discussion on how to run Node.js locally in the browser

[Recommended learning: "nodejs tutorial"]

Everything starts from receiving an email

A brief discussion on how to run Node.js locally in the browser

Early in the morning, I received an email. StackBlitz said that it was working with the teams at Next.js and Google to develop a new technology.
  • A few years ago, StackBlitzRealize that the network is heading towards a critical inflection point. The emergence of WebAssembly and new functional APIs makes it seem possible to write a WebAssembly-based operating system that is powerful enough to run Node.js entirely in the browser. We envisioned an advanced development environment that is faster, more secure and consistent than local environments to enable seamless code collaboration without the need to set up a local environment

Technology Named:WebContainers

  • WebContainers allow you to create complete Node.js environments that can be launched in milliseconds and instantly online and link-sharing with one click. This environment has VS Code's powerful editing experience, complete terminal, npm and other functions. It also runs entirely within your browser, resulting in some key benefits:
  • Faster than native environments. Builds are up to 20% faster and roll installs are over 5x faster compared to yarn/npm.
  • Node.js debugging in the browser. Seamless integration with Chrome DevTools enables native backend debugging, no installation or extension required.
  • Default is safe. All code execution occurs within the browser's secure sandbox, not on a remote VM or local binary.
  • Again, these environments do not run on the remote server. Instead, each environment is entirely contained within your web browser. That’s right: for the first time, the Node.js runtime itself is running natively in the browser.

    From now on, WebContainers is now in public beta. Current support includes Next.js, GraphQL, and Vanilla Node.js, and we are working with other open source projects to expand support

Why are thereWebContainers

Security
  • StackBlitz solves these problems by leveraging decades of speed and security innovation in browsers. All computation in StackBlitz happens immediately within the browser security sandbox and cannot be exploded onto your local machine. The model also unlocks some key development and debugging benefits (with more available in seconds).

A brief discussion on how to run Node.js locally in the browser

Unleash the power of your browser
  • Seamless Node.js debugging with Chrome DevTools

    • It turns out that browsers are really good at debugging Javascript. Shocking, I know ;) Integration with Chrome DevTools works out of the box by executing Node.js in the browser. No installation, no extensions, just native backend debugging in your browser

A brief discussion on how to run Node.js locally in the browser

Run the server in your browser In the device
  • actually. WebContainers contain a virtual TCP network stack that is mapped to the browser's ServiceWorker API, allowing you to create a live Node.js server on the fly and continue working even when you are offline. Because it runs entirely within the browser security sandbox, the server responds with less latency than localhost(!) and protects your web server from localhost scraping attacks
  • Millisecond startup time
  • Every page loads with a completely new environment

    • Goodbye rm -rf node_modules! WebContainer's built-in npm client is so fast that it runs a fresh installation every time the page loads, ensuring you get a clean environment every time. If something does go wrong with your environment, you can revert to a clean state just like you would with any other web application: click the Refresh button Keep working without an internet connection, on a plane or in the backseat in the rain
  • Using StackBlitz’s novel computing model, 100% of code execution happens in the browser’s safe sand in the box. This results in a faster, less restrictive development environment compared to on-premises while providing greater security, a very rare combination.
In fact, the default security posture is so solid that our embedded package manager is the first publicly available tool to resolve unsolved SAM issues in over five years Saccone's long-unresolved npm vulnerability
    Again, these environments do not run on the remote server. Instead, each environment is entirely contained within your web browser. That’s right: the Node.js runtime itself runs natively in the browser for the first time , but this time
  • WebContainers
  • put the direction of using this technology on
  • Node.js

    , I think it is of epoch-making significance

    In my opinion, this technology The main application direction in the future is to enable software around the world to run in places that could not run before. In the future, you may only need to install a Google Chrome browser on your computer

  • For more programming-related knowledge, please visit: Programming Video! !

The above is the detailed content of A brief discussion on how to run Node.js locally in the browser. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete