What is the correct way to import parse server with Ionic2


#1

I have googled it for a day and I found that most of them are outdated or not working.

forexample

http://alkon-tech.com/how-to-use-parse-javascript-sdk-with-ionic2-apps/

Install 2 additional modules necessary for nodejs environments
cd node-modules/parse/node_modules/ws
npm install --save utf-8-validate
npm install --save bufferutil

I don’t have node-modules/parse/node_modules/ws, so I guess it is node_module/ws, but when I fire nom install --save utf-8-validate

this error occur, same case as bufferutil

Failed at the bufferutil@1.2.1 install script ‘node-gyp rebuild’.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the bufferutil package,
npm ERR! not with npm itself.

And i googled for how to solve node-gyp rebuild . but so result.

2 : github parse ionic2 starter

I think this is a ionic1 version.

this one is pretty close but I can not find any Parse-related code inside.

3:
I have read all ionic2 parse server related post on this forum, there are no standard solution on this. Some of them
import {Parse} from ’ …/Provider/Parse’,

import prase.require(parse);

var parse = Parse.parse;

import prase.require(parse/node);

and so on…

I have tried all these thing but not working. So is there any tutorial on connecting Parse with Ionic2??


#2

Have you ever found something?


#3

yes I did. But I forgot the detail steps.

cd to your ionic2 project file

npm install parse —save
sudo ln -s /usr/lib/libSystem.B.dylib /usr/local/lib/libgcc_s.10.5.dylib
cd node_modules/ws
npm install —save utf-8-validate
npm install —save bufferutil

import {Component} from '@angular/core';
import {NavController} from 'ionic-angular';
declare var require:any;
var Parse = require('parse/node');

@Component({
  templateUrl: 'build/pages/home/home.html'
})
export class HomePage {
 constructor() {
    //Iinitialize connection to the server
   Parse.initialize('MP6H592QYgcXg3SwdqFO1BAUtQz1ukNFSAuKDR2n','28dyqDd66aGKf3zotsoYakbKPsb6BsTap1psszag', 'VCE1gayaYaMQFALEqvYm1cZs4Tf0jxjtZb66uoVM');
   Parse.serverURL = 'https://parseapi.back4app.com/';
 
   //Create class testObjClass
   var testObjClass = new Parse.Object.extend('TestObject');
 
   //Create instance of testObjClass
   var testObj = new testObjClass();
 
   //Add data you want to save as a hush
   testObj.set('key1','val1');
   testObj.set('key2','val2');
   testObj.set('key3','val3');
 
   //Save object to DB
   testObj.save().then(
     function(obj) {
       console.log("'New object created with objectId: " + testObj.id);
     },
     function(err) {
       console.log('Failed to create new object, with error code: ' + err.message);
     });
 }
}

#4

Thanks. Following this I get the error Uncaught ReferenceError: require is not defined


#5

Do npm install parse --save in your project directory

Then import parse using

import { Parse } from 'parse';

It is better to create an parse provider.

You can use this starter template as a guide. It is a simple GameScores application in ionic to get you started.

It shows how to create and read data from parse server. I also includes paging with ion-infinite-scroll scrolling.