Live data from Hacker News

WebContainers: Run Node.js natively in the browser

blog.stackblitz.com

151–160 of 238 posts

Re: WebContainers: Run Node.js natively in the browser

#151

Hi all- CEO of StackBlitz/author of this blog post here. Happy to answer any questions! (Also, thanks for posting this bpierre!)

You mention being able to use the debugger. How do I do this? The docs are very poor.

I dont see any way to set breakpoints. When i use a debugger statement and open inspector it breaks on transpiled/packaged code (its different to the actual file). This is a deal breaker for me at present. Am I doing something wrong?

(Using the http server template)

Re: WebContainers: Run Node.js natively in the browser

#152

Earlier quoted context omitted.

But you can do that same API emulation in regular browser JavaScript, too. What's the WASM intermediate buying here?

I think it is more complicated to emulate those api in normal browser environment compared to emulating some OS api for running node.js.

Why? It's literally JavaScript on both sides - what's complicated here?

Re: WebContainers: Run Node.js natively in the browser

#153
post #110

I used to teach web development and was always frustrated with just how much effort went into setting up a machine. It would be really nice if a developer could just include a script tag in their project that setup a TypeScript compiler inside service worker. I managed to get the basics down, even fixing relative import statements. Requests like localhost:3000/main.tsx would compile and cache on the fly. There were a…

Yes web developing is so hard... sudo apt install apache2 php libapache2-mod-php; vim /var/www/html/index.php

That's like saying that driving a car is easy. Foot on gas. Hands on wheel. Drive to destination.

Most things can be simplified to the raw essentials, doesn't mean you're going to achieve a result that people want or need.

Re: WebContainers: Run Node.js natively in the browser

#154

Earlier quoted context omitted.

I think it is more complicated to emulate those api in normal browser environment compared to emulating some OS api for running node.js.

Why? It's literally JavaScript on both sides - what's complicated here?

Because many node.js api are written in C/C++, it might be easier to implements OS features instead of rewriting in JS. This is just my assumption.

Re: WebContainers: Run Node.js natively in the browser

#155
To demonstrate the potential this needs a demo of a "middle-tier" service implemented in NodeJS. The service needs to talk to a MySQL database, and expose a Rest API to the web application.

If that works that means many intranet applications can be server-less. Both the JavaScript app and the "middle-tier" runs in the browser, and the middle-tier talks to MySQL server which is also on the intranet. All you need is a file server to serve the static JS files.

Re: WebContainers: Run Node.js natively in the browser

#156

Earlier quoted context omitted.

> the direction I'd like to see web development move is having a statically typed language that compiles to VM bytecode. Java… you want Java. And so the cycle continues!

That's a really good point. What we wanted all along was the JVM with a DOM API. We started with Java. It didn't gain any traction for browser scripting. They took "Java" out and called it JavaScript. Now we take the "script" out and call it WebAssembly. If someone in 1995 made Java a DOM-editing thing instead of an applet thing, we could have saved 25 years of running around in circles :) (Going back even further, w…

Hey applets could manipulate JavaScript data/the DOM. There is a bit of bark to the 'Java script' bite. It was very slow, though, sending through the JVM process and to the browser process each time you read or wrote a value (and the plugin that did this I think was in its own process - memory is hazy there).

Overall it's hard to say how Sun could have won here, perhaps acquiring macromedia and using Flash technology to make a browser that ran those cool portals out of the box, and hey scripted first-class in Java too btw ;-)

Re: WebContainers: Run Node.js natively in the browser

#157

To demonstrate the potential this needs a demo of a "middle-tier" service implemented in NodeJS. The service needs to talk to a MySQL database, and expose a Rest API to the web application. If that works that means many intranet applications can be server-less. Both the JavaScript app and the "middle-tier" runs in the browser, and the middle-tier talks to MySQL server which is also on the intranet. All you need is a…

If the middle-tier and the app are both written in JavaScript, and you're developing them both simultaneously in the browser, does it make sense for them to be communicating via REST any more?

Wouldn't it make more sense for the app to send SQL prepared statements to the database (via a tiny standardised wrapper on the server to enforce per-user permissions based on the authenticated session)?

It probably depends on whether other apps are requesting data from the same database, in which case it might make sense to convert from the relational model to JSON objects in a tier which exposes the objects over REST.

Re: WebContainers: Run Node.js natively in the browser

#158

I used to teach web development and was always frustrated with just how much effort went into setting up a machine. It would be really nice if a developer could just include a script tag in their project that setup a TypeScript compiler inside service worker. I managed to get the basics down, even fixing relative import statements. Requests like localhost:3000/main.tsx would compile and cache on the fly. There were a…

VS Code seems to allow this with Dev Containers. I can download a repo with a `.devcontainer.json` and be up and running in virtually no time, in a container.

Re: WebContainers: Run Node.js natively in the browser

#160
post #119

Earlier quoted context omitted.

> Everyone thought WASM would enable developers to write code in any language they wanted (with type checking and higher performance) and deploy it on the web. https://developer.mozilla.org/en-US/docs/WebAssembly/Concept... > WebAssembly is a different language from JavaScript, but it is not intended as a replacement. Instead, it is designed to complement and work alongside JavaScript, allowing web developers to take…

> WASM can't even talk to the DOM API directly For now. It's planned.

For existing code bases that don’t already do DOM manipulation (so, all of them) other parts of the Web API might be more useful, like the canvas, the video API, the RTC API etc.
Post reply on HN