How to install and use node js libraries?

I am developing an application using ionic. The platforms i target are mobile phones application (Not through the browser).My application depends on this library node-ytdl-core. I want to be able to call the library from my ts files .

Now i have some question :

  1. How can i install this js library ? What is the preferred way? i have researched a bit and i found this ways:

    • Use ionic add , but its deprecate.
    • Use bower to install the package via the git link. But the project doesn’t seems to rely on bower, but rather on npm.One more thing is that i cant find the library on bower, but its on NPM.
    • Use npm to install the library, for me this is the most straight forward method. But i have read that you shouldn’t mess with the npm dependencies because its manged only for the ionic project dependencies and native plugins.
  2. Can the ionic/cordova even run Node.js modules? It seems logical since cordova and ionic are written in Node.js, but i have read that its not the case, also there are repositories that add the support, like jxcore-cordova . Is this plugin necessary even if the module is written in pure js?

  3. How to access the library ?Lets say i have installed the library, how can i call it from ts ? since typescript can have javascript inside of it, and can run other js files, how should i call the lib ?Is it just easy as importing it regularly?
    import {ytdl-core} from 'node-ytdl-core'
    Or do i have to call node.js files separately?

Any help is much appreciated.

to be clear: if a package is available in npm it doesn’t have to be a real node-module. npm is only a package manager for node, so you can install depenencies via npm. ionic is written in pure javascript or ionic2 in typescript but is compiled to JS at the end of the day.

keep in mind there is javascript without dependencies to native APIs like filesystem and so on (is executable without nodejs installation on the target system). and javascript with relies on apis like the filesystem --> so you need nodejs installed.

Hey, thanks for the quick answer. If an app does rely on the filesystem, if i got it right, i would need some kind of node js installation, if i install the jxcore-cordova plugin, will it suffice for any node.js native calls ?

Hey I am also facing similar problem , I am using 1 javaScript library named JIMP which is written for Node js how can i use this integrate it in my ionic mobile application.

Hey Pankajdx123, I have exactly the same problem, I want to use JIMP in an ionic/cordova app but don’t know whether this is possible and if so how to do it.

I was wondering if you have, or anyone has, found a solution to this?