I am trying to follow this tutorial using nodejs and express: https://pusher.com/docs/beams/reference/web/#npm-yarn
First I did: npm install @pusher/push-notifications-web before adding the code.
But when I add this code in the index.js file:
import * as PusherPushNotifications from "@pusher/push-notifications-web";
const beamsClient = new PusherPushNotifications.Client({
instanceId: "<YOUR_INSTANCE_ID_HERE>",
});
beamsClient.start().then(() => {
// Build something beatiful 🌈
});
I get this error:
SyntaxError: Cannot use import statement outside a module
It’s also not very clear to me from the tutorial if the code has to be in the frontend or the backend. I tried both but got the same result.
How can I fix this problem?
>Solution :
The error is caused by the fact that you’re trying to use ES module specific features in a regular CommonJS file (the default behavior in Node.js). However, what you’re looking at is the Web SDK for Pusher which won’t help you achieve your goals.
You need the server SDK for Node.js – https://pusher.com/docs/beams/reference/server-sdk-node/.