Is it possible to write Chrome applications using node.js modules?

I want to write a Chrome application, but I also want to interact with some .NET code using Edge.js. Now I tried this in a Nodejs app, but can't figure out how to do this in a Chrome app.

I watched Paul Kinlan’s YouTube video ( hours of running Chrome Apps - NodeJS in chrome packages ) but cannot get the code to run, I also tried the browser without success.

Is there a working sample that uses any of the node modules in a Chrome application (as the available resources look older).

Thanks in advance, Manoj.

+6
source share
1 answer

I ran the code written for node.js inside chrome-packaged applications and used modules published in npm using either a browser or webpack.

The only real difficult bit for me traditionally is to export functions for use by my web application, since you do not have access to require() . Usually I just create a special module that exports all the global characters that I want to receive, and use them as my entry point.

For example, using webpack, I would create a file called globals.js :

 module.exports = exports = { a: require('a'), b: require('b'), ... } 

Then create webpack.config.js :

 module.exports = { context: __dirname + "/js", entry: { globals: [ "globals.js", ], }, output: { // Make sure to use [name] or [id] in output.filename // when using multiple entry points path: __dirname + "/js/generated", filename: "[name].bundle.js", chunkFilename: "[id].bundle.js", library: "[name]", libraryTarget: "umd", } }; 

Then I can package and include the generated package in my application and now use the global variable globals .

I'm not sure if Edge.js works, but I would not think it would be possible for a webpack / browser in a web / chrome application, because they do not support built-in bindings and interprocess communication is much different. I just don't know how this works.

(But you can probably implement your own interop with .net applications, using possibly another IPC)

+4
source

Source: https://habr.com/ru/post/973084/


All Articles