TypeError: undefined is not a function (near '..._httpIn.default.createServer...')

Viewed 34

I just followed this technic to use Core Node JS Modules in React Native Apps.

Project structure

enter image description here

My code :

import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';
import crypto from './crypto-in';
import http from './http-in';
import fs from './fs-in';


// Create an instance of the http server to handle HTTP requests
let app = http.createServer((req, res) => {
// Set a response type of plain text for the response
res.writeHead(200, {'Content-Type': 'text/html'});
fs.createReadStream('index.html').pipe(res)
});

// Start the server on port 3000
app.listen(3000, '127.0.0.1');
console.log('Node server running on port 3000');

const secret = 'open-sesame';
const hash = crypto.createHmac('sha256', secret)
               .update('abcdefg')
               .digest('hex');
console.log("*********************************** crypto = "+hash+" 
***************************************");

AppRegistry.registerComponent(appName, () => App);

If I run it comes an error like this :

 BUNDLE  ./index.js

 WARN  The provided value 'ms-stream' is not a valid 'responseType'.
 WARN  The provided value 'moz-chunked-arraybuffer' is not a valid 'responseType'.
 ERROR  TypeError: undefined is not a function (near '..._httpIn.default.createServer...')
 ERROR  Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication). A frequent cause of the error is that the application entry file path is incorrect.
  This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native.
ERROR  Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication). A frequent cause of the error is that the application entry file path is incorrect.
This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native.

Why this error comes ?

How can I solve this error ?

0 Answers
Related