2

Currently I'm developing an application using vue.js (MEVN)

I need to implement CoAP and OPC-UA client in vue.js Unfortunately, I can't find a suitable client library for vue.js But, I did found the library for node.js.

So, this pop up a question to me, is it possible to use the node.js library to vue.js ?

For example:

https://github.com/mcollina/node-coap

My guess, it is not... But they have the same language. So, I'm really not sure.

Please share your thought about this, or any other possible library if existed that can be used with vue.js

Thank you !

Lyn
  • 507
  • 3
  • 15
  • 2
    https://stackoverflow.com/q/20079381/438992 I doubt this has changed. You may want to change your title since browsers can use many NodeJS libraries. – Dave Newton Jul 25 '18 at 10:36
  • @DaveNewton Thank you for your references and suggestion ! But, I don't know what is the right title for it. – Lyn Jul 26 '18 at 00:49
  • Can it use the library you're talking about. Many, many node libraries work in the browser. – Dave Newton Jul 26 '18 at 01:22

1 Answers1

1

Vue.js can use NPM library, i.e. a library that was published on NPM registry and is installed with NPM or Yarn package managers.

There's no strict definition of Node library. Usually this means that a library is intended to be used in Node.js and uses Node.js features. Sometimes it's possible to mock or polyfill them on client side (streams, buffers). Package internals should be examined in order to make a decision. E.g. joi is Node library but doesn't depend on Node.js features for the most part and is suitable for browser use with a few adjustments at build step.

node-coap documentation clearly states that the package uses Node.js http module, which isn't available on client side:

client and server library for CoAP modeled after the http module

Notice that it refers to CoAP client, not to client-side environment (a browser).

Since Vue.js supports server-side rendering, it's possible to use Node libraries on server side. This will work if some units don't need to be used on client side or they are used differently (load data from filesystem on server side and via AJAX request on client side). This approach won't work in this case because Node.js library functionality is needed on client side.

Estus Flask
  • 206,104
  • 70
  • 425
  • 565
  • Thank you for your explanation. Although I'm not fully understand your meaning, since I'm originally an embedded programmer. More or less, maybe I got what you mean. From my guess, in short, what you mean is as long as the node.js library did not use specific functionality from node.js itself, It could be used on Vue.js But even if it do so, we still can tweak it if possible. I hope I got the right conclusion. – Lyn Jul 26 '18 at 00:34
  • You're welcome. That's correct. As it was mentioned in the comment, this functionality likely cannot be achieved in browser https://stackoverflow.com/q/20079381/438992 . So you'll need to pass your request through Node server. – Estus Flask Jul 26 '18 at 00:43
  • Looks like it will be quite troublesome, at least for me. But I will try that ! – Lyn Jul 26 '18 at 00:52