https://github.com/krlan2789/express-ws-app
Express - WebSocket Server Application
https://github.com/krlan2789/express-ws-app
expressjs nodejs postgresql websocket websocket-server
Last synced: about 2 months ago
JSON representation
Express - WebSocket Server Application
- Host: GitHub
- URL: https://github.com/krlan2789/express-ws-app
- Owner: krlan2789
- License: mit
- Created: 2023-09-16T11:18:26.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-10T20:09:14.000Z (7 months ago)
- Last Synced: 2024-11-10T21:18:54.425Z (7 months ago)
- Topics: expressjs, nodejs, postgresql, websocket, websocket-server
- Language: JavaScript
- Homepage: https://erlankurnia.github.io/article/1/WebSocket%20Example%20Project
- Size: 36.1 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 1. Express WebSocket App Example
## 1.1. **Specs**
- NodeJS `16.20.0`
- NPM `8.19.4`
- ExpressJS `4.17.1`
- NodeJS WebSocket Library `8.2.3`
- PostgreSQL `12.14`## 1.2. **Getting Started**
1. Clone project repository :
```shell
$ git clone https://github.com/krlan2789/express-ws-app.git
```2. Switch to the project directory :
```shell
$ cd express-wss-app
```3. Install dependencies :
```shell
$ npm install
or
$ npm i
```## 1.3. **Database Configuration**
1. Duplicate the `.env_example` or create new file, then rename it to `.env`.
2. Change the value as needed :```ini
DB_HOST=localhost # database hostname or ip
DB_PORT=5432 # postgresql port
DB_NAME=postgres # database name
DB_USERNAME=root # database username
DB_PASSWORD=12345678 # database passwordCONNECTION_PORT=8765 # node.js app port
```## 1.4. **Running Applications**
1. Switch to the project directory :
```shell
$ cd express-wss-app
```2. Start on development mode :
```shell
$ npm run dev
```3. Start on production mode :
```shell
$ npm start
```4. Start on production mode using pm2 ([required pm2 package](https://github.com/Unitech/pm2)) :
```shell
$ npm start:pm2
```5. Open browser, use websocket tester tools, then fill in the url with `[ws/wss]://[ip/hostname]:[port]?token=user_token`.
```http
Example :HTTP -> ws://localhost:8765?token=user1240635408404344554
HTTPS -> wss://localhost:8765?token=user1240635408404344554
```Or, run `npm run test:ws` on terminal.
6. Visit [this article](https://erlankurnia.github.io/note/2/WebSocket%20Service%20on%20VPS) to run the app on VPS/Cloud hosting/etc.