Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to import node npm module in angular 6

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!!!

like image 737
WasiF Avatar asked Dec 13 '18 08:12

WasiF


1 Answers

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

like image 165
Auqib Rather Avatar answered Nov 15 '22 05:11

Auqib Rather