How to use nodejs `net` module in reactjs web application

305 views
Skip to first unread message

Minions Media

unread,
Feb 10, 2021, 10:11:40 AM2/10/21
to nw.js
I was trying to use nodejs `net` module in my reactjs web application to integrate socket communication (TCP) - not with the Websocket.

I did the following things to integrated the `nw.js` with my `reactjs` application

- Added `nw` as a dependency
- package.json looks like below


When I tried to launch the app in the browser, it throws an error that net.Socket is not defined.
and when I debug this issue, I came to know that nodejs net module is an empty object.

Is there any way to use net module in the browser with nw.js. 


Minions Media

unread,
Feb 10, 2021, 10:12:03 AM2/10/21
to nw.js

package.json


{
"name": "desktop-chat-nw",
"version": "0.1.0",
"private": true,
"chromium-args": "--mixed-context",
"window": {
"show": true,
"frame": true,
"width": 800,
"height": 600,
"min_width": 450,
"min_height": 320,
"position": "center",
"resizable": true,
"icon": "./assets/icon-48x48.png",
"toolbar": "true"
},
"dependencies": {
"@material-ui/core": "^3.9.3",
"@material-ui/icons": "^3.0.2",
"@material-ui/styles": "^3.0.0-alpha.10",
"nw": "0.38.2-sdk",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-redux": "^7.0.3",
"react-scripts": "3.0.0",
"redux": "^4.0.1",
"redux-thunk": "^2.3.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"nw-start": "nw .",
"launch": "npm-run-all -l -p start nw-start"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"dotenv": "^8.0.0",
"npm-run-all": "^4.1.5"
}
}
Reply all
Reply to author
Forward
0 new messages