@RealFighter64 wrote:
Hi,
I have a local MongoDB database (at the moment it's local, anyway) and I want to access it though an Ionic app. However, I've tried to usenpm install mongodb
and it works when is use the node.js CLI, however when I follow the Node.js MongoDB quickstart, it throws an error saying that require is not defined. Here is the code:var MongoClient = require('mongodb').MongoClient; var assert = require('assert'); // angular.module is a global place for creating, registering and retrieving Angular modules // 'starter' is the name of this angular module example (also set in a <body> attribute in index.html) // the 2nd parameter is an array of 'requires' angular.module('starter', ['ionic']) .run(function($ionicPlatform) { $ionicPlatform.ready(function() { if(window.cordova && window.cordova.plugins.Keyboard) { // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard // for form inputs) cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); // Don't remove this line unless you know what you are doing. It stops the viewport // from snapping when text inputs are focused. Ionic handles this internally for // a much nicer keyboard experience. cordova.plugins.Keyboard.disableScroll(true); } if(window.StatusBar) { StatusBar.styleDefault(); } }); var url = 'mongodb://localhost:27017/test'; MongoClient.connect(url, function(err, db) { assert.equal(null, err); console.log("Connected correctly to server."); db.close(); }); }) .controller('MainController', ['$scope', function($scope) { }])
Posts: 1
Participants: 1