I am new to expo and am trying to add a server.js
file to my app so that I can make calls from my front end to my back end and retrieve some data. I created a server.js
file (see below), and in my package.json
file I changed the top line to "main": "server.js"
. (Previously it was "main": "node_modules/expo/AppEntry.js"
).
However, I am getting the following error when I try to run the app on a simulator:
The package at "node_modules/express/lib/express.js" attempted to import the Node standard library module "events". It failed because React Native does not include the Node standard library.
Here is my server.js code:
const express = require('express');
const app = express();
app.use(express.static('public'));
let port = process.env.port || 3000;
import 'expo/build/Expo.fx';
import registerRootComponent from 'expo/build/launch/registerRootComponent';
import { activateKeepAwake } from 'expo-keep-awake';
import App from './App';
if (__DEV__) {
activateKeepAwake();
}
registerRootComponent(App);
console.log("hello");
// listen for requests :)
const listener = app.listen(port, () => {
console.log('Your app is listening on port ' + listener.address().port);
});
Can anyone help me figure out how to fix this?