how to import node npm module in angular 6

11,436
import * as findLocalDevices from 'local-devices'

and inside any method use it as

ngOnInit() {
   console.log(findLocalDevices());
}

you may require to install other packages also os child_process / mz

Share:
11,436
WasiF
Author by

WasiF

Updated on June 17, 2022

Comments

  • WasiF
    WasiF almost 2 years

    I have installed the package

    npm install local-devices
    

    and imported it in angular.json as

    "scripts": [
        "./node_modules/local-devices/index.js"
    ]
    

    and declared as global variable in src/typings.d.ts

    declare let findLocalDevices: any
    

    Below, package files structure and index.js of local-devices package

    enter image description hereenter image description here

    then tried to use it in a component as

    console.log(findLocalDevices())
    

    but got error

    findLocalDevices is not defined

    How to import it, please guide!!!

  • WasiF
    WasiF over 5 years
    Module not found: Error: Can't resolve 'child_process' in '\node_modules\mz'. How to resolve this?