sahat / hackathon-starter

A boilerplate for Node.js web applications
MIT License
34.89k stars 8.18k forks source link

Fix Foursquare integration #888

Closed YasharF closed 5 years ago

YasharF commented 6 years ago

Upgrading node-foursquare from 0.3.3 to 0.4.3 in package.json breaks the project:

$ npm start

> hackathon-starter@5.1.2 start /mnt/c/temp/hackathon-starter
> node app.js

/mnt/c/temp/hackathon-starter/controllers/api.js:16
const { Venues, Users } = require('node-foursquare')({
                                                    ^

TypeError: require(...) is not a function
    at Object.<anonymous> (/mnt/c/temp/hackathon-starter/controllers/api.js:16:53)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object.<anonymous> (/mnt/c/temp/hackathon-starter/app.js:35:23)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
    at startup (internal/bootstrap/node.js:266:19)
peterblazejewicz commented 6 years ago

I know it seems strange, but this fixes the issue:

diff --git a/controllers/api.js b/controllers/api.js
index 009d112..22565d1 100644
--- a/controllers/api.js
+++ b/controllers/api.js
@@ -1,3 +1,4 @@
+
 const { promisify } = require('util');
 const request = require('request');
 const cheerio = require('cheerio');
@@ -13,7 +14,8 @@ const clockwork = require('clockwork')({ key: process.env.CLOCKWORK_KEY });
 const paypal = require('paypal-rest-sdk');
 const lob = require('lob')(process.env.LOB_KEY);
 const ig = require('instagram-node').instagram();
-const { Venues, Users } = require('node-foursquare')({
+require('babel-polyfill');
+const { Venues, Users } = require('node-foursquare').default()({
   secrets: {
     clientId: process.env.FOURSQUARE_ID,
     clientSecret: process.env.FOURSQUARE_SECRET,
diff --git a/package.json b/package.json
index 97f446a..6d7eb77 100644
--- a/package.json
+++ b/package.json
@@ -18,6 +18,7 @@
     "@fortawesome/fontawesome-free": "^5.2.0",
     "@ladjs/bootstrap-social": "^7.0.2",
     "@octokit/rest": "^15.9.5",
+    "babel-polyfill": "^6.26.0",
     "bcrypt-nodejs": "^0.0.3",
     "body-parser": "^1.18.3",
     "bootstrap": "^4.1.3",
@@ -42,7 +43,7 @@
     "mongoose": "^5.2.7",
     "morgan": "^1.9.0",
     "multer": "^1.3.0",
-    "node-foursquare": "^0.3.3",
+    "node-foursquare": "^0.4.3",
     "node-linkedin": "^0.5.6",
     "node-sass": "^4.9.3",
     "node-sass-middleware": "^0.11.0",

It looks like the issue is with node-foursquare tooling details: https://github.com/babel/babel/issues/5085

YasharF commented 6 years ago

This should probably be fixed in node-foursquare. Would you mind creating an issue in that repo? https://github.com/clintandrewhall/node-foursquare

peterblazejewicz commented 6 years ago

https://github.com/clintandrewhall/node-foursquare/issues/37

clintandrewhall commented 6 years ago

You should be able to move to v0.4.4 and proceed. Let me know if you have any further issues with the recent rewrite! I'm including a blog post that helped me understand how to move forward:

https://blog.kentcdodds.com/misunderstanding-es6-modules-upgrading-babel-tears-and-a-solution-ad2d5ab93ce0

YasharF commented 6 years ago

Considering that the scope of the integration fix seems to have increased, it is also valid to ask the bigger question: Is foursquare integration something to keep or replace with another API integration such as Yelp. Hackahton-Starter initiated in 2013 and looking at google trends since 2013 Foursquare's use seem to have gone through a sharp decline, while Yelp seems to be somewhat holding:


image


image


niallobrien commented 6 years ago

It's a good question, though I do know that there are many other companies that rely on Foursquare's data & API.

On Tue 28 Aug 2018, 09:37 Yashar Fakhari, notifications@github.com wrote:

Considering that the scope of the integration fix seem to have increased, it is also valid to ask the bigger question: Is foursquare integration something to keep or replace with another API integration such as Yelp. Hackahton-Starter initiated in 2013 and looking at google trends since 2013 Foursquare's use seem to have gone through a sharp decline, while Yelp seems to be somewhat holding:

[image: image] https://user-images.githubusercontent.com/6448697/44710943-20e20380-aa62-11e8-9d9b-82319ef64f62.png

[image: image] https://user-images.githubusercontent.com/6448697/44711054-61418180-aa62-11e8-886f-758cf19a857f.png

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/sahat/hackathon-starter/issues/888#issuecomment-416499362, or mute the thread https://github.com/notifications/unsubscribe-auth/ABdHpSlVF0kgGV0nafbOFzNw12nnJ8F4ks5uVQE-gaJpZM4VulFp .

clintandrewhall commented 6 years ago

If you don't mind me weighing in: I know FSQ has waned a bit in the consumer space, but they're pretty strong in venue data and very strong in location detection. I'm not sure if Google searches are the best indicator of apps that use Foursquare integration.

I recently attended HackMidwest, a popular hackathon that took place in Kansas City, and Foursquare had developers there and sponsored prizes... so providing this integration seems germane.

Maybe the right call would be an audit of big-ticket sponsors of hackathons to determine what to provide out of the box?

clintandrewhall commented 6 years ago

Perhaps Alexa, Elastic, Twilio and Box/Dropbox should be considered, for example?

http://www.hackmidwest.com/#prizes

YasharF commented 6 years ago

I just noticed that Samsung's Bixby Vision on their flagship phones lists Foursquare as one of the underlying data sources as well. We need to fix the integration 👍

screenshot_20180911-213321_bixby vision

YasharF commented 5 years ago

The API example is now using the Foursquare REST APIs directly with https://github.com/sahat/hackathon-starter/commit/4cdb5b98ea45ba70e6d50ced69a613789c39c97b