WasiF
WasiF

Reputation: 28859

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

Upvotes: 6

Views: 14902

Answers (1)

Auqib Rather
Auqib Rather

Reputation: 396

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

Upvotes: 9

Related Questions