Ce contenu n'est pas disponible dans la langue sélectionnée.

Chapter 8. Node.js basics in CodeReady Studio


Node.js is an event-based, asynchronous I/O framework and is used to develop applications that run JavaScript on the client and server side. This allows the application to reuse parts of the code and to avoid switching contexts. Node.js is commonly used to create applications such as static file servers, messaging middleware, HTML5 game servers, web application framework, and others.

CodeReady Studio supports Node.js application development using the npm package installer and offers a built-in debugging tool to identify and fix issues with applications.

The following section describes how to:

  • Create a new JavaScript project.
  • Create a new package.js file.
  • Create a new JavaScript file.
  • Import an existing JavaScript project.
  • Run a Node.js application.

Prerequisites

  • Installed npm.
  • Installed Node.js.

    To install the prerequisites on RHEL, use:

    # yum install npm nodejs
    Copy to Clipboard Toggle word wrap

8.1. Creating a new JavaScript project

The following section describes how to create a new JavaScript project in CodeReady Studio.

Procedure

  1. Start CodeReady Studio.
  2. Click File New Other.

    The New window appears.

  3. Enter JavaScript in the search field.
  4. Select JavaScript Project.
  5. Click the Next button.

    The Create a JavaScript project window appears.

  6. Name your project.

    All other fields are populated automatically.

  7. Click the Finish button.

    The Open Associated Perspective window appears.

  8. Click the Open Perspective button.

Your newly created JavaScript project is now listed in the Project Explorer view.

8.2. Creating a package.js file

The following section describes how to create a new package.json file in CodeReady Studio.

Procedure

  1. Start CodeReady Studio.
  2. Click File New Other.

    The New window appears.

  3. Enter npm in the search field.
  4. Select npm Init.
  5. Click the Next button.

    The npm Initialization Wizard window appears.

  6. Click the Browse Workspace button to select the base directory for the package.json file.
  7. Click the Finish button.

    The Open Associated Perspective window appears.

  8. Click the Open Perspective button.

Your newly created package.js file is now displayed in the CodeReady Studio editor.

Additional resources

8.3. Creating a new .js file

The following section describes how to create a new .js file in CodeReady Studio.

Procedure

  1. Start CodeReady Studio.
  2. Click File New File.

    The Create New File window appears.

  3. Select a parent folder for the file.
  4. Name the file.

    For example index.js.

  5. Click the Finish button.

Your newly created .js file is now displayed in the CodeReady Studio editor.

8.4. Importing an existing Node.js application

The following section describes how to import an existing Node.js application.

Procedure

  1. Start CodeReady Studio.
  2. Click File Import.

    The Import window appears.

  3. Expand the General folder.
  4. Select Existing Project into Workspace.
  5. Click the Next button.
  6. Click the Browse button to locate your existing project.
  7. Select the path to your project in the Projects field.
  8. Click the Finish button.

Verification steps

  1. Click Window Perspective Open Perspective Other.

    The Open Perspective window appears.

  2. Select JavaScript.
  3. Click the Open button.

    The Project Explorer view appears.

Your newly imported Node.js application is now listed in the Project Explorer view.

8.5. Running a Node.js application

The following section describes how to run a Node.js application in CodeReady Studio.

Procedure

  1. Start CodeReady Studio.
  2. Open Project Explorer.
  3. Right-click target project Run as Node.js Application.

The Console view appears running your Node.js application.

8.6. Debugging a Node.js application

CodeReady Studio includes a debugger to help identify and resolve the issues.

The following section describes how to debug Node.js applications in CodeReady Studio.

Procedure

  1. Start CodeReady Studio.
  2. Open Project Explorer.
  3. Expand the target project.
  4. Right-click the index.js Debug as Node Program.

    The Console view appears, displaying the error log.

Retour au début
Red Hat logoGithubredditYoutubeTwitter

Apprendre

Essayez, achetez et vendez

Communautés

À propos de la documentation Red Hat

Nous aidons les utilisateurs de Red Hat à innover et à atteindre leurs objectifs grâce à nos produits et services avec un contenu auquel ils peuvent faire confiance. Découvrez nos récentes mises à jour.

Rendre l’open source plus inclusif

Red Hat s'engage à remplacer le langage problématique dans notre code, notre documentation et nos propriétés Web. Pour plus de détails, consultez le Blog Red Hat.

À propos de Red Hat

Nous proposons des solutions renforcées qui facilitent le travail des entreprises sur plusieurs plates-formes et environnements, du centre de données central à la périphérie du réseau.

Theme

© 2025 Red Hat