File tree Expand file tree Collapse file tree
blog/26-05-17/almostnode/ex Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < meta charset ="UTF-8 ">
5+ < title > Almostnode in the Browser</ title >
6+ </ head >
7+ < body >
8+ < h1 > Open your browser console to see the output!</ h1 >
9+
10+ < script type ="module ">
11+ // Load almostnode directly from an ESM-friendly CDN
12+ import { createContainer } from 'https://esm.sh/almostnode' ;
13+
14+ async function init ( ) {
15+
16+ const container = createContainer ( ) ;
17+
18+ // Run some Node.js code right here in the client browser
19+ const result = await container . execute ( `
20+
21+ const events = require('events');
22+ const emitter = new events.EventEmitter();
23+
24+ emitter.on('greet', (name) => {
25+ console.log('Node Event Emitter says: Hello ' + name);
26+ });
27+
28+ emitter.emit('greet', 'World');
29+
30+ ` ) ;
31+
32+ }
33+
34+ init ( ) ;
35+
36+
37+ </ script >
38+ </ body >
39+ </ html >
40+
You can’t perform that action at this time.
0 commit comments