Greg Trasuk's Weblog A Collection of Technology, Art and Culture Things

Using a Module written for Node.js in an Angular App

by Greg Trasuk

Posted on Friday Mar 30, 2018 at 09:09PM in Technology

Sometimes we have a module that's written for use under "Node.js", that I'd also like to use inside an Angular (meaning Angular 5, not AngularJS) application.

The module I want to use is called 'utils-for-aprs'. Add it to the Node setup:

  npm install --save utils-for-aprs

It would be kind of cool to have a 'typings' file for this new module; I'll have to look into how to do that. For now, just being able to use it is good enough.

The module will use the events module. Under Node, this is built-in to Node's core modules library, but we need to let webpack find it.

  npm install --save events

As it happens, I also want to use the node-style event emitter inside an Angular service, so load the typings file as well:

  npm install --save @types/events

Now in the service, we can use the following:
  import {EventEmitter} from 'events';
  import {WebSocketAprsDataEndpoint} from 'utils-for-aprs';

... and webpack will find the required modules and include them in the 'vendor' bundle when we do a 'ng build'.

No one has commented yet.
Comments are closed for this entry.