Products Technologies Demo Docs Blog Support Company

Creating an Angular Document Editor Application with a Node.js WebSocket Server

This tutorial shows how to create an Angular application that uses the Document Editor with a Node.js WebSocket server.

Creating an Angular Document Editor Application with a Node.js WebSocket Server

The npm package for using the document editor in Angular applications can be used with an ASP.NET (Core) backend or a Node.js server to handle the WebSocket requests. This tutorial will show you how to create an Angular application that uses a Node.js backend server to handle the requests.

Creating the Node.js Project

Prerequisites

  1. Install Node.js® and npm, if not done before.

  1. Open a Node.js command prompt, create an empty folder called "node-websocket-server", navigate into and type in the following command to install the document editor:

    npm install @txtextcontrol/tx-websocket-server
  2. Type in the following command to install Express, the minimalist web framework for node:

    npm install express
  3. Create a new file named main.js in the project's root folder, copy the following code into this JavaScript file and save it:

    const { WebSocketServer } = require('@txtextcontrol/tx-websocket-server');
    const express = require('express');
    const app = express();
    const server = app.listen(8080);
    
    var wsServer = new WebSocketServer(server);
  4. Back in the command prompt, start the Node.js application by typing in the following command:

    node main.js

Creating the Angular Application

Prerequisites

  1. Open a Command Prompt and install the Angular CLI globally by typing in the following command:

    npm install -g @angular/cli
  1. Open a Command Prompt and create a new project and default app by typing in the following command:

    ng new my-editor-app

    Follow the questions in the command prompt by answering them with "y" to add Angular routing and Enter to confirm CSS as your preferred stylesheet format.

  2. Change into the created folder by typing in the following command:

    cd my-editor-app
  3. Install the TX Text Control document editor package by typing in the following command:

    ng add @txtextcontrol/tx-ng-document-editor

    Supported Angular Versions

    Are you getting an error similar to this?

    ERESOLVE unable to resolve dependency tree

    You have two options here:

    1. Please check the supported Angular versions of tx-ng-document-editor and downgrade Angular and the global Angular CLI version to a version that will satisfy the requirement.

    2. Force the installation of the package. Read more about that here:
      Document Editor and Viewer with Newer Versions of Angular CLI

  4. Open this folder in Visual Studio Code by typing in the following command:

    code .
  5. In Visual Studio Code, open the file src -> app -> app.component.html, add replace the complete content with the following code and save it:

    <tx-document-editor
      width="1000px"
      height="500px"
      webSocketURL="ws://localhost:8080/TXWebSocket">
    </tx-document-editor>

    Backend Server

    In the code above, we are using the Node.js backend that we created in the first step. If you have been using a different port and endpoint path, you should replace them.

  6. Back in the command prompt, start the Angular application by typing in the following command:

    ng serve --open

Stay in the loop!

Subscribe to the newsletter to receive the latest updates.

Angular

Integrate document processing, editing, sharing, collaboration, creation, electronic signatures, and PDF generation into your Angular Web applications.

Learn more about Angular

Related Posts

AngularASP.NETNode.js

Creating a WebSocket Server Project with Node.js

This article shows how to create the required WebSocket server project for Angular applications using Node.js.


AngularDocument EditorNode.js

Angular: Loading and Saving Local Documents

This article shows how to load and save local documents using the Angular version of the document editor.


AngularDocument EditorSPA

Reuse Persistent Document Editor Components in Angular SPA Applications

An Angular Single Page Application (SPA) dynamically updates the web page without reloading by loading all necessary resources once. This article demonstrates how to reuse persistent Document…


AngularASP.NETBlazor

Building an ASP.NET Core Backend (Linux and Windows) for the Document Editor…

This article shows how to create a backend for the Document Editor and Viewer using ASP.NET Core. The backend can be hosted on Windows and Linux and can be used in Blazor, Angular, JavaScript, and…


AngularJavaScriptDocument Editor

Getting Started: Document Editor Version 33.0 with Angular CLI 19.0

This article shows how to use the TX Text Control Document Editor version 33.0 npm package for Angular within an Angular CLI 19.0 application. It uses the trial backend running on our servers, but…