Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Investigate running NodeJS / Express locally #33

Open
tuukka opened this issue Jun 1, 2017 · 3 comments
Open

Investigate running NodeJS / Express locally #33

tuukka opened this issue Jun 1, 2017 · 3 comments
Assignees

Comments

@tuukka
Copy link

tuukka commented Jun 1, 2017

This would help e.g. running Digitransit UI locally.

@0is1 0is1 self-assigned this Jun 5, 2017
@0is1
Copy link
Contributor

0is1 commented Jun 7, 2017

Well, there's some hacks that try to enable node.js core modules and their dependencies in RN see: https://github.com/mvayngrib/rn-nodeify or https://github.com/philikon/ReactNativify

But there are limitations and concerns like

  const keyPair = bitcoin.ECPair.fromWIF(
    'L1uyy5qTuGrVXrmrsvHWHgVzW9kKdrp27wBC7Vs6nZDTF2BRUVwy'
  );
  const tx = new bitcoin.TransactionBuilder();

  tx.addInput(
    'aa94ab02c182214f090e99a0d57021caffd0f195a81c24602b1028b130b63e31',
    0
  );
  tx.addOutput('1Gokm82v6DmtwKEB8AiVhm82hyFSsEvBDK', 15000);
  tx.sign(0, keyPair);

  const expected = '0100000001313eb630b128102b60241ca895f1d0ffca2170d5a0990e094f2182c102ab94aa000000006b483045022100aefbcf847900b01dd3e3debe054d3b6d03d715d50aea8525f5ea3396f168a1fb022013d181d05b15b90111808b22ef4f9ebe701caf2ab48db269691fdf4e9048f4f60121029f50f51d63b345039a290c94bffd3180c99ed659ff6ea6b1242bca47eb93b59fffffffff01983a0000000000001976a914ad618cf4333b3b248f9744e8e81db2964d0ae39788ac00000000';
  const actual = tx.build().toHex();

  return new Promise((resolve) => {
    process.nextTick(() => {
      resolve(actual === expected);
    });
  });

So I'm not so convinced about this approach.

And I'm not sure if it's even possible to run modules like express in RN, even in theory? Because for example http module is rewritten by https://github.com/jhiesey/stream-http and you don't obviously have there things like http.createServer (what you need with express) because RN runtime is basically Safari/Chrome browser.

@wswoodruff
Copy link

@0is1 Have you tried using babel-plugin-rewrite-require or babel-plugin-module-alias to let you require browserify Node package shims? Since babel is separate from react-native it seemed like the best solution to me. Here's and example with rewrite-require: philikon/ReactNativify#4 (comment)

and here's an example with module-alias: https://github.com/wswoodruff/strangeluv-native/blob/master/.babelrc

@wswoodruff
Copy link

As for running Express locally, not sure how that would benefit you guys.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants