What is the method for reaching the electron process from a different npm process?

Recently, I developed a script that sets up a TCP server to listen for incoming requests and triggers a Windows notification upon receiving one. Here's the code snippet:

const notifier = require('node-notifier');
const path = require('path');
const net = require('net');
const port = 7070;
const host = '';

const server = net.createServer();
server.listen(port, host, () => {
    console.log('The TCP Server is now operational on port ' + port + '.');
});

let sockets = [];
server.on('connection', function(sock) {
    console.log('CONNECTED: ' + sock.remoteAddress + ':' + sock.remotePort);
    sockets.push(sock);

    sock.on('data', function(data) {
        var tryCatch = true;
        try {
            JSON.parse(data);
        } catch (err) {
            tryCatch = err;
        }
        if (tryCatch == true) {
            var JSONdata = JSON.parse(data);
            if (JSONdata["action"] == "notification") {
                notifier.notify({
                        title: 'Received Message',
                        message: JSONdata["message"],
                        icon: path.join(__dirname, 'icon.png'),
                        actions: ["OK", "Cancel"]
                    },
                    (err, data) => {
                        console.log('Waiting...');
                        console.log(JSON.stringify({ err, data }));
                        sock.write(JSON.stringify({ err, data }));
                        sock.write('\r');
                        sock.destroy();
                    }
                );
            } else if (JSONdata["action"] == "closeServer") {
                sock.destroy();
                server.close();
            }
        } else {
            sock.write(tryCatch.message);
            sock.destroy();
        }
    });

    // Implement a 'close' event handler for this socket instance
    sock.on('close', function(data) {
        let index = sockets.findIndex(function(o) {
            return o.remoteAddress === sock.remoteAddress && o.remotePort === sock.remotePort;
        })
        if (index !== -1) sockets.splice(index, 1);
        console.log('CLOSED: ' + sock.remoteAddress + ' ' + sock.remotePort);
        // server.close();
    });
});

The script performs flawlessly. Now, my intention is to integrate it with my electron application. I aim to interact with the Electron app from this npm process, such as opening a page. However, I'm unsure about accessing the Electron process externally, specifically from another npm process. Any guidance or assistance in this matter would be greatly appreciated.

Answer №1

It's quite straightforward. Even though I couldn't find a direct solution on accessing another process, you can simply prevent or block any attempts by the user to open another window. In such cases, you have the option to create your own window instead and utilize the ipcMain and ipcRender modules to transmit data to the desired window.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Every time I hit the refresh button, I find myself forcefully logged out

After switching from using localStorage to cookies in my React JS web app, I am experiencing an issue where I get logged out whenever I refresh the page. Even though the cookies are still stored in the browser, the authentication process seems to be failin ...

Seeking assistance in configuring Reddit OAuth using Node.js

I've been facing difficulties with this issue for a few days now and I couldn't find the necessary information in the Reddit API documentation to obtain oauth access using node. After registering my application with Reddit, I set 'http://loc ...

Executing MySQL queries synchronously in Node.js

When working with NodeJS and mysql2 to save data in a database, there are times when I need to perform database saves synchronously. An example of this is below: if(rent.client.id === 0){ //Save client connection.query('INSERT INTO clients (n ...

Creating a Dockerfile for Node8 and Nginx Integration

Greetings to everyone. I am facing an issue with a Dockerfile that has NODE 8, as it requires the installation of Nginx in the container for enabling gzip. However, the solution provided at https://dev.to/subhransu/nevertheless-subhransu-maharana-coded-5ea ...

Executing NodeJS custom middleware to show parent function being called

Goal: Showcase the parent function of a middleware function shared = require('./RoutFuctions'); app.post('/link', shared.verifyToken, (req, res) => { ... } In the middleware function exports.verifyToken = functio ...

What is the destination of next(err) in Express when managing an error?

http://expressjs.com/guide/error-handling.html function logErrors(err, req, res, next) { console.error(err.stack); next(err); } This excerpt can be found in the expressJS documentation. I am curious to know what exactly happens after calling next ...

Is it possible to execute Grunt/Gulp on my PHP 5.4 cartridge?

Exploring the capabilities of OpenShift has been exciting, but I am eager to incorporate a JavaScript task runner into my deployment process. Although NPM is present in the platform, every attempt to install my package.json or npm install grunt results in ...

Enhancing a knex/bookshelf model with custom functions in a node/express application

I've defined my model like this: const User = db.Model.extend({ tableName: 'users', hasSecurePassword: true }); module.exports = User; With this setup, I can perform actions such as const User = require("../models/user"); ...

Ensure that the package.json file is updated if the local package version is not

As someone who is relatively new to node js and npm, I have noticed that there can be discrepancies between the packages installed on my system and those being installed by npm install or package.json. I am looking for a way to check the version of my loc ...

What is the best way to require users to click one of the toggle buttons in a form?

Is it possible to require the user to click one of the toggle buttons in a React form? I want to display an error if the user tries to submit the form without selecting a button. Even though I tried using "required" in the form, it didn't work as expe ...

The name field in the request body is currently undefined

Currently, I am working on developing a basic blog page using technologies such as ejs, JavaScript, Node.js, Express, and body-parser. While working on passing inputs to the command line, specifically for the title, I encountered an issue. When I used req ...

What is the best way to implement multilanguage support in nodejs without relying on cookies or external modules?

Currently, I am in the process of transitioning all my projects to node.js in order to enhance my JavaScript skills. Using Node.js along with the Express module, one of my clients who runs a translation company has requested that I incorporate two language ...

Node.js is having trouble locating a module that has been installed

Upon transferring my node.js application to a different PC (where it functioned flawlessly on the development machine) and manually installing all the necessary dependencies, I encountered an error when attempting to run it: C:\Users\myself>n ...

Building a Personalized Docker Image for Node.js and Selenium-Webdriver: Step-by-Step Guide

Having trouble getting my automation project to run in Jenkins. Issues with Docker images downloaded from the Internet and Linux agent compatibility with my Windows environment. I manually downloaded Google Chrome/Chromedriver in the build, but still can& ...

ERROR: The specified module '../node-v11-darwin-x64/node_sqlite3.node' could not be located

Our server has a modified version of the Ghost blogging platform with updated content and design. I recently transferred the blog's app folder to my local machine and followed the provided instructions, which appeared to be straightforward. Quickstar ...

What is the method for including the sources directory within the require() scope in npm?

Upon examining my directory structure, the following layout is revealed: package.json /src a.js /test test_a.js The contents of package.json are as follows: { "name": "foo", "scripts": { "test": "mocha" }, "devDependencies": { "mocha ...

Managing requests between different domains with Admin-on-rest on localhost port

My API development setup involves using Hapijs (Version 17.2.3) for the backend and the Admin-on-rest framework in the frontend. The Hapijs API runs on http://localhost:3000, while Admin-on-rest is hosted at http://localhost:3001. When trying to display t ...

Inject additional information following user authentication

Hello there! I have successfully developed a REST API using Node.js and StrongLoop, along with an Angular.js based app. After a user logs in, the server sends an accessToken which is stored in cookies. For every request, the accessToken is sent and verif ...

Is it possible in Angular to generate a module and component without including a CSS file in a single command?

Is it possible to generate a Module linked to a component without automatically creating a css file? For example, the default method I've been using involves: ng generate module name / ng generate component name This results in the typical componen ...

What are some potential problems that could arise when making a POST request for signing authentication in a MERN stack using JWT?

I'm currently in the process of developing a social media application using the MERN stack. To ensure the functionality of the backend API, I am utilizing POSTMAN. Here is an overview of the dependencies outlined in the package.json file: { "na ...