<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Gbose Israel on Medium]]></title>
        <description><![CDATA[Stories by Gbose Israel on Medium]]></description>
        <link>https://medium.com/@eezzy2k3?source=rss-94338efee3d1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dmbNkD5D-u45r44go_cf0g.png</url>
            <title>Stories by Gbose Israel on Medium</title>
            <link>https://medium.com/@eezzy2k3?source=rss-94338efee3d1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 01:58:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@eezzy2k3/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Developing an API for a restaurant where users can find restaurants closest to them]]></title>
            <link>https://medium.com/@eezzy2k3/developing-an-api-for-a-restaurant-where-users-can-find-restaurants-closest-to-them-13101431d238?source=rss-94338efee3d1------2</link>
            <guid isPermaLink="false">https://medium.com/p/13101431d238</guid>
            <dc:creator><![CDATA[Gbose Israel]]></dc:creator>
            <pubDate>Sun, 09 Oct 2022 19:13:01 GMT</pubDate>
            <atom:updated>2022-10-09T20:14:16.071Z</atom:updated>
            <content:encoded><![CDATA[<p>Developing an API for a restaurant where users can find restaurants closest to them</p><p>Let us go on a quick journey to build an API for a restaurant where the users can locate restaurants based on location</p><p>Stack used: Nodejs, Express, and MongoDB</p><p>we start by creating our app</p><p>From our terminal, we install express, mongoose,node-geocoder, and dotenv</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XgpK9vHJN7hV82llJ2n6DA.png" /><figcaption>packagejson</figcaption></figure><p>npm i express mongoose node-geocoder dotenv</p><p>we set up our app.js</p><p>require(“dotenv”).config()</p><p>const app = express()</p><p>app.use(express.json())</p><p>app.listen(5000,()=&gt;{<br> console.log(`port is listening on port 5000`)<br>})</p><p>Setting up environment variables and mongoose</p><p>In our root directory, we create a folder named config and a file called config.js inside the config folder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3CDYOwp3qJz5ugxP3HpsCw.png" /></figure><p>const mongoose = require(“mongoose”)</p><p>const connectDb = ()=&gt;{<br> mongoose.connect(process.env.MONGO_URL)<br> console.log(“DB connected”)<br>}</p><p>module.exports = connectDb</p><p>now we set our dotenv file</p><p>Open a file in the root directory and name it .env</p><p>The dotenv is a zero-dependency module that <strong>loads environment variables from a .env file into the process .env</strong></p><p>My .env file looks like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8fnSQyP8GuJy8O0TlIwzrw.png" /></figure><p>we will talk about the GEOCODER_PROVIDER and GEOCODER_Api_KEY later in the section.</p><p>Let us set up our Schema</p><p>const mongoose = require(“mongoose”)</p><p>const locationSchema = mongoose.Schema({<br> restaurantName:String,<br> address:{<br> type:String,<br> required:true<br> },<br> location:{<br> type: {<br> type: String,<br> enum: [‘Point’],<br> required: true<br> },<br> coordinates: {<br> type: [Number],<br> required: true,<br> index:”2dsphere”<br> },<br> formattedAddress:String,<br> street:String,<br> city:String,<br> state:String,<br> zipcode:String,<br> country:String<br> }<br> <br>},{timestamps:true})<br>locationSchema.pre(“save”,async function(next){<br> <br> this.address = undefined<br> next()<br> })</p><p>const Restaurant = new mongoose.model(“Restaurant”,locationSchema)</p><p>module.exports = Restaurant</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*guonUr3TCzktAFBIIIcdnw.png" /><figcaption>schema</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qoMFZege7cbxXjYOGnpeYw.png" /><figcaption>schema</figcaption></figure><p>The location field is the field we need to use the node-geocoder as stated in the npm official documentation <a href="https://www.npmjs.com/package/node-geocoder">https://www.npmjs.com/package/node-geocoder</a>. we set the address to be undefined because we don&#39;t want the address to be returned whenever a request is made but instead the formatted address by node-geocoder.</p><p>Let us create a folder named utils in the root directory and open a file and call it geoCoder.js</p><p>In the geoCoder.js file, we import the node-geocoder dependency</p><p>const NodeGeocoder = require(“node-geocoder”)</p><p>we set our options</p><p>const options = {<br> provider:process.env.GEOCODER_PROVIDER,<br> httpAdapter:”https”,<br> apiKey:process.env.GEOCODER_API_KEY,<br> formatter:null<br>}</p><p>const geocoder = NodeGeocoder(options)</p><p>module.exports = geocoder</p><p>In the options, we choose a provider. you can use Mapquest, OpenCage, or Google. Mapquest is simple, but Google requires a credit card. Open an account with mapquest to get your API key <a href="http://developer.mapquest.com/user/me/apps">http://developer.mapquest.com</a></p><p>In your .env file enter your provider and API key</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8fnSQyP8GuJy8O0TlIwzrw.png" /><figcaption>.env file</figcaption></figure><p>lets us create our controller. Open a folder name it src in it open a file and name it locationController.js or any name you want.in the file, we will do all our logic</p><p>const Restaurant = require(“../models/LocationModel”)</p><p>const geocoder = require(“../utils/geocoder”)</p><p>const createRestaurant = async(req,res)=&gt;{<br> try {<br> // use node-geocoder to get formatted address<br> const loc = await geocoder.geocode(req.body.address) //geocoder converts the address to a formatted address using the address we input<br> let location = {<br> type : “Point”,<br> coordinates:[loc[0].longitude,loc[0].latitude],<br> formattedAddress:loc[0].formattedAddress,<br> street:loc[0].streetName,<br> city:loc[0].city,<br> state:loc[0].stateCode,<br> zipcode:loc[0].zipcode,<br> country:loc[0].countryCode<br> }<br> <br> req.body.location = location<br> <br> <br> // create a new restaurant<br> const restaurant = await Restaurant.create(req.body)<br> <br> res.status(201).json({success:true,data:restaurant}) <br> <br> } catch (error) {<br> console.log(error.message)<br> }<br>}</p><p>we set up the logic to get restaurants by location using zip code and also stating the distance we are searching within either in km or miles</p><p>const restaurant = async(req,res)=&gt;{<br> try {<br> <br> // use geo-code to get latitude and longitude<br> const {zipcode,distance, unit} = req.params<br> const loc =await geocoder.geocode(zipcode)<br> const lat = loc[0].latitude<br> const lng = loc[0].longitude<br> let radius;<br> <br> <br> // divide distance by the radius of the earth to get the radius either in km/mi<br> if(unit == “km”){<br> radius = distance/6378<br> }if(unit == “mi”){<br> radius=distance/3963<br> }<br> <br> // find a restaurant within the location<br> const restaurant = await Restaurant.find({<br> location : { $geoWithin: { $centerSphere: [ [lng,lat], radius] } }<br> })</p><p>res.status(200).json({success:true,Number:restaurant.length,data:restaurant})<br> } catch (error) {<br> res.json(error.message)<br> console.log(error.message)<br> }<br>}</p><p>module.exports = {createRestaurant,restaurant}</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*39Kd8KU0OPklencsRgaM0A.png" /><figcaption>controller</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3IxiNJ4EGVFxR6Ap-yW0NA.png" /><figcaption>controller</figcaption></figure><p>we are almost there. let us create our router file. In the src folder create a file and name it locationRouter.js</p><p>const {createRestaurant,restaurant} = require(“../controller/locationController”)</p><p>const express = require(“express”)</p><p>const router = express.Router()</p><p>router.route(“/”)<br>.post(createRestaurant)</p><p>router.get(“/:zipcode/:distance/:unit”,restaurant)</p><p>module.exports = router</p><p>we export the router to our app.js and we are done.</p><p>require(“dotenv”).config()<br>const express = require(“express”)<br>const connectDb = require(“./config/config”)<br>const locationRouter = require(“./src/router/locationRoute”)</p><p>const app = express()</p><p>app.use(express.json())</p><p>connectDb()</p><p>app.use(“/api/v1”,locationRouter)</p><p>app.listen(5000,()=&gt;{<br> console.log(`port is listening on port 5000`)<br>})</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ksVQmC4iZpuW4huMKoCzuA.png" /><figcaption>app.js</figcaption></figure><p>Let us test using postman</p><p><a href="https://drive.google.com/file/d/1fkh1TWDRtVJM5QEppY33soJWzyCrZG8b/view?usp=sharing">Untitled.mp4</a></p><p>We have come to the end of our API.</p><p>here is a link to the GitHub repo <a href="https://github.com/eezzy2k3/restaurantApp">https://github.com/eezzy2k3/restaurantApp</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=13101431d238" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating a subscription based music api using nodejs express and mongoDb]]></title>
            <link>https://medium.com/@eezzy2k3/creating-a-subscription-based-music-api-using-nodejs-express-and-mongodb-a1bc13fc5e84?source=rss-94338efee3d1------2</link>
            <guid isPermaLink="false">https://medium.com/p/a1bc13fc5e84</guid>
            <dc:creator><![CDATA[Gbose Israel]]></dc:creator>
            <pubDate>Fri, 30 Sep 2022 18:50:47 GMT</pubDate>
            <atom:updated>2022-10-02T05:01:40.355Z</atom:updated>
            <content:encoded><![CDATA[<p>I will be taking us on a journey of how to create a subscription based music api using express and mongoDb.</p><p>These are the packages used</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v7SByvDVRMHjj4geQFQQOg.png" /><figcaption>package.json</figcaption></figure><p>set up your server</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xW6fZ2najzn6uZs8R164tg.png" /><figcaption>app.js</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O4cqvqJtsJcEmoLD73XzNw.png" /><figcaption>app.js</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qlNzHeSw9eVyYCDw-cn_nQ.png" /><figcaption>user model</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kWaNEc7eA8zuh2ITWdlgig.png" /><figcaption>user model</figcaption></figure><p>lets create the music schema</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K6OzA_JRV7P4EbdE-NecOg.png" /><figcaption>music schema</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hf-wSrdGldrr2vZDuGHhEg.png" /><figcaption>music schema</figcaption></figure><p>subscription model</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9LzGj32pQmiEwWQkk8V4xw.png" /><figcaption>subscription model</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e_WpA7zReOx6TikdEjzPyw.png" /><figcaption>plan model</figcaption></figure><p>we have all our models set now let us create the controllers</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pU9Uox20qGOPqf91AXaSnw.png" /><figcaption>user controller</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DEY21vCKRe89nhrZwBRuCw.png" /><figcaption>auth controller</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hf4MSIFurztMjwFJWm1e-A.png" /><figcaption>auth controller</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SMrGBe2Ee6OZW0mJ6aUhbQ.png" /><figcaption>subscription controller</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*adh80VcJ9nY0r4Jx8lZcfA.png" /><figcaption>subscription controller</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BhE2JFNAv46itMWzjKgdGw.png" /><figcaption>plan controller</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7n_iCNXQL-LgNFecioJToQ.png" /><figcaption>plan controller</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_k_O3KgnsX4Bl8YyHWPu_g.png" /><figcaption>plan controller</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZLLyV1fsYNmE4fp4pU8V1g.png" /><figcaption>plan controller</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i6GJioa7To5-zd1VRG1JWw.png" /><figcaption>plan controller</figcaption></figure><p>lets go to the routes</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xnGrJFpC1uX7Io-HSAmBow.png" /><figcaption>auth route</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XFuA2zmTKNVRumVvKQvWzQ.png" /><figcaption>music route</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p43-92M0mt0cYptpomUmLQ.png" /><figcaption>subscription route</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uc1YdpTROdOoCh5Gk4bbRw.png" /><figcaption>user route</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OBN9QGrCsRNnXRrIlIrteQ.png" /><figcaption>plan route</figcaption></figure><p>A cron job is use to schedule task or automate repetitive task.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GRNr666VoywbtvLOfXTVBw.png" /><figcaption>cronjob</figcaption></figure><p>Hope you learnt something. Here is the GitHub link below</p><p><a href="https://github.com/eezzy2k3/musicSubscriptionApi">https://github.com/eezzy2k3/musicSubscriptionApi</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a1bc13fc5e84" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>