This tutorial uses Visual Studio Code that can be downloaded for free.
Creating the WebSocket Server Project
-
Open a Node.js command prompt, create an empty folder called "websocket-server", navigate into and type in the following command to install Express, the minimalist web framework for node:
npm i express -
Now, install the WebSocket Server package of TX Text Control:
npm i @txtextcontrol/tx-websocket-server -
Open this folder in Visual Studio Code by typing in the following command:
code . -
In Visual Studio Code, create a new file named app.js in the project's root folder:
Copy the following code into this JavaScript file and save it:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersconst { WebSocketServer } = require('@txtextcontrol/tx-websocket-server'); const express = require('express'); const app = express(); const server = app.listen(8080); var wsServer = new WebSocketServer(server); -
Back in the command prompt, start the Node.js application by typing in the following command:
node app.js
Connecting the Angular Application
When connecting an Angular based document editor application with this Node.js WebSocket Server, add this endpoint to the webSocketURL parameter:
<tx-document-editor | |
width="1000px" | |
height="500px" | |
webSocketURL="ws://localhost:8080/TXWebSocket"> | |
</tx-document-editor> |