StefanRetief / nodebowl

A in-browser lib that emulates the Node.js API includes fs, require, etc.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

nodebowl

nodebowl

Put node in a bowl.

nodebowl is a in-browser lib that emulates the Node.js API includes fs, require, etc. It can run many Node.js lib in browser,eg: webpack in browser.

This project just started,please consider starring the project to show your ❤️ and support if you like it.

Getting Started

$ npm install nodebowl
<script src="node_modules/nodebowl/dist/nodebowl.js"></script>
<script>
  const { fs, run } = window.nodebowl;
  fs.writeFileSync('/foo.js', `
    module.exports = 1;
  `);
  fs.writeFileSync('/index.js', `
    const num = require('./foo');
    console.log(num);
  `);
  run('/index.js');
</script>

or import it

import nodebowl from 'nodebowl';

const { fs, run } = window.nodebowl;

API

run(file[, args][, options])

  • file <string> The name or path of the executable file to run.

  • args <string[]> List of string arguments.

  • options <object>

    • cwd <string> Current working directory.Default: /
    • env <object> Environment key-value pairs.
run('index.js'); // node index.js

run('index.js', {
  env: {
    NODE_ENV: 'dev'
  }
}); // NODE_ENV=dev node ./index.js

run('./dir/index.js', ['--v']); // node ./dir/index.js --v

helpers.installFromZip(url)

  • url <string> The zip url.

When you need to download the zip file like node_modules, you can use this helper method.

Other API

Other API emulates Node.js API, includes: fs, path, etc...

Alternatively, you can use the require method just as you are using Node.js.

Examples

  • simple examples/simple
  • webpack examples/webpack

Dev

$ yarn
$ yarn dev
$ open http://localhost:8080/examples/simple/index.html

Contributors

Welcom issue and pr, more details will be explained later.

About

A in-browser lib that emulates the Node.js API includes fs, require, etc.


Languages

Language:JavaScript 100.0%