javascriptnode.jsvisual-studiocordovataco

I'm using Cordova (VS TACO) and want to access Node.js OS methods but receive "require is not defined"


I generally work in the backend, so am new to Cordova and Node.js. I thought that Cordova effectively runs off Node, but if this is the case, why doesn't the "require" method work?

I've used the "Blank App (Apache Cordova)" template within Visual Studio 2015 which runs without a problem and have been happily playing around with it. Now that I'm trying to utilise an aspect of Node though - specifically the line:

var os = require('os')

I receive the error "0x800a1391 - JavaScript runtime error: 'require' is undefined".

Any help would be appreciated as I suspect that I'm missing a few basics....

Thanks.


Solution

  • Cordova scripts used to make a Cordova build etc. use Node.js for package management. The Cordova JavaScript libraries available in your client app (typically a mobile app) do not use Node.js and are not built on top of Node.js.