mongodb / stitch-examples

MongoDB Stitch Examples
Apache License 2.0
138 stars 89 forks source link

node no_hardware.js #79

Open ghost opened 5 years ago

ghost commented 5 years ago

I am getting the error as shown as below Please guide, the command I ran was

node no_hardware.js

snipper

jjlytle commented 5 years ago

same here update these examples

ghost commented 5 years ago

Did not get you, I have updated all pulled complete repo. How to sort out this error

jjlytle commented 5 years ago

The idea is when you use import statements in node js code you have now required ES6 and to babel to be used to compile your code. you do not mention this in you tutorial. And it is not setup correctly on github in the package.json file either. Look at the comments there. Why not just try to do the tutorial as Witten in a fresh folder and you will see as written this tutorial will not work and could never have worked as written. If you are not familiar with node or java script enough find someone who is and fix it. I was thinking about using your products but there is a serious lack of clear documentation.

On December 6, 2018 at 1:10:12 AM, Rahul Mehta (notifications@github.com) wrote:

Did not get you, I have updated all pulled complete repo. How to sort out this error

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/mongodb/stitch-examples/issues/79#issuecomment-444801282, or mute the thread https://github.com/notifications/unsubscribe-auth/APLYbAbFFqW7K9MWFetjOlLpIOE6x1Hkks5u2N7BgaJpZM4ZDK35 .

ghost commented 5 years ago

Thanks for respondingI tried googling and installation of bable etc using npmBut still struggling

On Thursday, December 6, 2018, 9:19:18 AM GMT, Jeffrey Lytle <notifications@github.com> wrote:  

The idea is when you use import statements in node js code you have now required ES6 and to babel to be used to compile your code. you do not mention this in you tutorial. And it is not setup correctly on github in the package.json file either. Look at the comments there. Why not just try to do the tutorial as Witten in a fresh folder and you will see as written this tutorial will not work and could never have worked as written. If you are not familiar with node or java script enough find someone who is and fix it. I was thinking about using your products but there is a serious lack of clear documentation.

On December 6, 2018 at 1:10:12 AM, Rahul Mehta (notifications@github.com) wrote:

Did not get you, I have updated all pulled complete repo. How to sort out this error

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/mongodb/stitch-examples/issues/79#issuecomment-444801282, or mute the thread https://github.com/notifications/unsubscribe-auth/APLYbAbFFqW7K9MWFetjOlLpIOE6x1Hkks5u2N7BgaJpZM4ZDK35 .

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

jjlytle commented 5 years ago

I have already figured it out and rewrote the program taking out the es6 features. There is also another mistake as well in the tutorial it says to name your function logTemperatureReading and in the code the function is named ImpWrite, so it will never call the function for someone just learning and unfamiliar with your error structure this is very confusing.

On December 6, 2018 at 1:54:41 AM, Rahul Mehta (notifications@github.com) wrote:

Thanks for respondingI tried googling and installation of bable etc using npmBut still struggling

On Thursday, December 6, 2018, 9:19:18 AM GMT, Jeffrey Lytle < notifications@github.com> wrote:

The idea is when you use import statements in node js code you have now required ES6 and to babel to be used to compile your code. you do not mention this in you tutorial. And it is not setup correctly on github in the package.json file either. Look at the comments there. Why not just try to do the tutorial as Witten in a fresh folder and you will see as written this tutorial will not work and could never have worked as written. If you are not familiar with node or java script enough find someone who is and fix it. I was thinking about using your products but there is a serious lack of clear documentation.

On December 6, 2018 at 1:10:12 AM, Rahul Mehta (notifications@github.com) wrote:

Did not get you, I have updated all pulled complete repo. How to sort out this error

— You are receiving this because you commented. Reply to this email directly, view it on GitHub <https://github.com/mongodb/stitch-examples/issues/79#issuecomment-444801282

, or mute the thread < https://github.com/notifications/unsubscribe-auth/APLYbAbFFqW7K9MWFetjOlLpIOE6x1Hkks5u2N7BgaJpZM4ZDK35

.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/mongodb/stitch-examples/issues/79#issuecomment-444814291, or mute the thread https://github.com/notifications/unsubscribe-auth/APLYbBF58qNL7oobmPYndYzjIU8bLdrAks5u2OlJgaJpZM4ZDK35 .

jjlytle commented 5 years ago

// Set-up the Stitch client *// here is the code besides running. *npm install // also run. npm install mongodb-stitch-server-sdk // then everything should work as advertised const { Stitch, AnonymousCredential, } = require('mongodb-stitch-server-sdk');

// Send sample data while within this loop function generateData(stitchClient) { // Create a random temperature and humidity data point with // temp ranging from -20 to 20 °C const myData = { "temp" : Math.floor(Math.random() 20) - 20, "humid" : Math.floor(Math.random() 100) };

// Print to the console console.log(myData);

// Simulate write to MongoDB every 2 minutes stitchClient.callFunction("logTemperatureReading", [myData] ).then( setTimeout(() => generateData(stitchClient), 120000) ); }

// Use the API Key to load data const stitchClient = Stitch.initializeDefaultAppClient(“");

stitchClient.auth.loginWithCredential(new AnonymousCredential()) .then(() => { generateData(stitchClient); });

On December 6, 2018 at 2:00:28 AM, Jeffrey John Lytle (jjlytle@uw.edu) wrote:

I have already figured it out and rewrote the program taking out the es6 features. There is also another mistake as well in the tutorial it says to name your function logTemperatureReading and in the code the function is named ImpWrite, so it will never call the function for someone just learning and unfamiliar with your error structure this is very confusing.

On December 6, 2018 at 1:54:41 AM, Rahul Mehta (notifications@github.com) wrote:

Thanks for respondingI tried googling and installation of bable etc using npmBut still struggling

On Thursday, December 6, 2018, 9:19:18 AM GMT, Jeffrey Lytle < notifications@github.com> wrote:

The idea is when you use import statements in node js code you have now required ES6 and to babel to be used to compile your code. you do not mention this in you tutorial. And it is not setup correctly on github in the package.json file either. Look at the comments there. Why not just try to do the tutorial as Witten in a fresh folder and you will see as written this tutorial will not work and could never have worked as written. If you are not familiar with node or java script enough find someone who is and fix it. I was thinking about using your products but there is a serious lack of clear documentation.

On December 6, 2018 at 1:10:12 AM, Rahul Mehta (notifications@github.com) wrote:

Did not get you, I have updated all pulled complete repo. How to sort out this error

— You are receiving this because you commented. Reply to this email directly, view it on GitHub <https://github.com/mongodb/stitch-examples/issues/79#issuecomment-444801282

, or mute the thread < https://github.com/notifications/unsubscribe-auth/APLYbAbFFqW7K9MWFetjOlLpIOE6x1Hkks5u2N7BgaJpZM4ZDK35

.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/mongodb/stitch-examples/issues/79#issuecomment-444814291, or mute the thread https://github.com/notifications/unsubscribe-auth/APLYbBF58qNL7oobmPYndYzjIU8bLdrAks5u2OlJgaJpZM4ZDK35 .

ghost commented 5 years ago

I am still getting error, please guide.

ghost commented 5 years ago

iot

Please find attachment with error

jjlytle commented 5 years ago

Besides using this code as your new no_hardware.js also make sure the name of your function is logTemperatureReading. In the original no_hardware.js it was named impWrite and would never have connected to the logTemeratureReading function the tutorial has you create. you must also install the MongoDB Server side sdk. so run

nom install mongodb-stitch-server-sdk

at the command line. You must also turn on AnonymousCredential setting in your Stitch app under getting started tab, as in this code I am using AnonymousCredential instead of an API Key easier to get working for now. and of course put you where it belongs in the code.

// Set-up the Stitch client
// here is the code besides running. npm install
// also run. npm install mongodb-stitch-server-sdk
// then everything should work as advertised
const {
Stitch,
AnonymousCredential,
} = require('mongodb-stitch-server-sdk');

// Send sample data while within this loop
function generateData(stitchClient) {
// Create a random temperature and humidity data point with
// temp ranging from -20 to 20 °C
const myData = {
"temp" : Math.floor(Math.random() * 20) - 20,
"humid" : Math.floor(Math.random() * 100)
};

// Print to the console
console.log(myData);

// Simulate write to MongoDB every 2 minutes
stitchClient.callFunction("logTemperatureReading", [myData] ).then(
setTimeout(() => generateData(stitchClient), 120000)
);
}

// Use AnonymousCredential to load data
const stitchClient = Stitch.initializeDefaultAppClient('<your-app-id>');

stitchClient.auth.loginWithCredential(new AnonymousCredential())
.then(() => {
generateData(stitchClient);
});