Node.js and Socket.io make full-duplex communication easy (full 2-way, like a cell phone conversation)
- Node.js (and npm, included with Node)
- A browser (e.g., Chrome)
- A text editor with a terminal (e.g., VS Code)
- Still no build tools needed
- Node.js non-blocking event loop supports many concurrent requests
- Socket.io makes full duplex communication easy
- Express provides middleware, static-file serving, and routing.
- Multiple browser clients can exchange messages immediately.
Open default terminal (if Windows use PowerShell) in the root project folder and run:
npm update
npm install
npm audit fixIn the same terminal, start your app.
npm run devKeep this terminal open while using the application. Nodemon starts the server and restarts it when application files change. A successful startup should report something similar to:
[nodemon] starting `node app.js`
Server listening on 0.0.0.0:3003
Open http://localhost:3003/The address 0.0.0.0 means that the server is listening on all available IPv4 network interfaces.
Do not enter http://0.0.0.0:3003/ in the browser - it's
is a server binding address rather than a browser destination.
Optional: Click to Verify Server
Leave Terminal 1 open with the server running. Open a second terminal in the root project folder. Verify that the server is accepting connections on port 3003.
If Windows PowerShell, use:
Test-NetConnection localhost -Port 3003If macOS or Linux use:
nc -zv 127.0.0.1 3003Success might appear like this:
WARNING: TCP connect to (::1 : 3003) failed
ComputerName : localhost
RemoteAddress : 127.0.0.1
RemotePort : 3003
InterfaceAlias : Loopback Pseudo-Interface 1
SourceAddress : 127.0.0.1
TcpTestSucceeded : TrueOr request the page directly from the server:
curl.exe -i http://localhost:3003/A successful request should start with:
HTTP/1.1 200 OKUse the results to help identify problems:
TcpTestSucceeded : Falsemeans the server is not accepting connections on port 3003.HTTP/1.1 404 Not Foundmeans Express could not find the requested page.HTTP/1.1 500 Internal Server Errormeans the application encountered an error.HTTP/1.1 200 OKmeans Express successfully returned the page.
- Open a web browser.
- Go to the URL: http://127.0.0.1:3003/ or http://localhost:3003/.
Open PowerShell as Admin, run ipconfig. Locate your IPv4 address. Invite others to interact with your hosted chat app.