Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Jun 19 2021 12:31
    @texas2010 banned @therichaverma
  • Jun 19 2020 20:05
    @krisb1220 banned @Gastony
  • May 14 2020 22:39
    @bjorno43 banned @minitechtips_twitter
  • May 14 2020 22:38
    @bjorno43 banned @real-action
  • Feb 01 2020 00:26
    @bjorno43 banned @Ndoua
  • Jan 07 2020 03:10
    @bjorno43 banned @doctor-sam
  • Aug 17 2019 09:32
    User @bjorno43 unbanned @linkin-park
  • Aug 17 2019 01:43
    @bjorno43 banned @linkin-park
  • Jun 20 2019 21:20
    @bjorno43 banned @shenerd140
  • May 10 2019 09:13
    @bjorno43 banned @zhaokunhaoa
  • Apr 27 2019 19:47
    @mstellaluna banned @zhonghuacx
  • Apr 25 2019 17:12
    @mstellaluna banned @cmal
  • Jan 08 2019 22:00
    @mstellaluna banned @dertiuss323
  • Dec 15 2018 23:36
    @mstellaluna banned @18835579411
  • Dec 13 2018 23:57
    @mstellaluna banned @brandon6190
  • Oct 12 2018 05:50
    @bjorno43 banned @NACH74
  • Oct 05 2018 23:02
    @mstellaluna banned @JomoPipi
  • Sep 16 2018 12:21
    @bjorno43 banned @yash-kedia
  • Sep 16 2018 12:16
    @bjorno43 banned @vnikifirov
  • Sep 05 2018 08:13
    User @bjorno43 unbanned @androuino
Kris Baillargeon
@krisb1220
@realariharrison_twitter Google maps has a feature in it's API that allows you to draw on it. Based on the thickness of the lines, it looks like Redfin uses that feature. They just programmatically draw the borders.
I'm not sure how they do it, I don't know anything about the Maps API, lol. That's just a guess based on a quick Google search.
Ankur sharma
@ankur1163
I am trying very simple post request in express, mongoose
const router = require('express').Router();
const User = require('../model/User')
 router.post('/register',async (req,res)=>{
    console.log("entered")
   const user = new User ({
       name:req.body.name,
       email:req.body.email,
       password:req.body.password
   })
    try{
        console.log("try")
        const savedUser = await user.save();
       console.log("got",savedUser)
       res.send(savedUser)


    }catch(err){
        res.status(400).send(err)
    }
}) 

router.post(
    '/new', function (req, res) {
        res.send('POST request to the auth homepage')
})


router.post(
    '/', function (req, res) {
        res.send('POST request to the auth homepage')
})




module.exports = router;
/new route works, / route works
/register doesnt work, the postman just stuck
cancelled or called out
this code particularly
try{
        console.log("try")
        const savedUser = await user.save();
       console.log("got",savedUser)
       res.send(savedUser)
i can see try in my console
after that nothing happens in console
proquibas
@proquibas
try:
user.save()
.then(result => {
console.log(result);
res.send(result);
}).catch(err => {
console.log(err);
res.status(400).send(err);
});
Ankur sharma
@ankur1163
@proquibas
this is the code now
     password:req.body.password
   })
    try{
        user.save()
        .then(result=>{
            console.log(result);
            res.send(result)
        }).catch(err=>{
            console.log(err);
            res.status(400).send(err)
        })
but its still stuck
proquibas
@proquibas
your req.body has the user data you are trying to send in the post method? are you connected to mongodb?
Ankur sharma
@ankur1163
yes i think so
this is my environemtn variable
DB_CONNECT = 'mongodb+srv://deved:rhino11@cluster0-ur19v.mongodb.net/test?retryWrites=true&w=majority';
this is my code
const express = require('express');
const app = express();

const authRoute = require('./routes/auth')
const mongoose = require('mongoose');
const dotenv = require("dotenv");
dotenv.config();

//connect to DB 
mongoose.connect(process.env.DB_CONNECT,
{useNewUrlParser: true},()=>console.log("connected to db"))

app.use(express.json())
app.use('/api/user',authRoute)
// app.post('/hello', function (req, res) {
//     res.send('POST request to the homepage')
//   })
app.listen(3000,()=>console.log("up and running"))
how do i check if i am connected to mongodb database correctly?
this url i have checked quiet few times
mongodb+srv://deved:rhino11@cluster0-ur19v.mongodb.net/test?retryWrites=true&w=majority';
and its correct
@proquibas
Ankur sharma
@ankur1163
can someone tell me
why this code isnt working
router.post('/register',async (req,res)=>{
    console.log(mongoose.connection.readyState);
    console.log("entered")
   const user = new Usersignup ({

       email:req.body.email,
       password:req.body.password
   })
    try{
         const emailExist = await User.findOne({email:email})
        console.log("emailexist",emailExist)
        if(emailExist){
            console.log("email exists")
            return res.status(400).send("email already exists")
        }
        else{
            console.log("email doesnt exist")
            user.save()
        .then(result=>{
            console.log(result);
            res.send(result)
        }).catch(err=>{
            console.log(err);
            res.status(400).send(err)
        })

        } 


    /*     user.save()
    .then(result=>{
        console.log(result);
        res.send(result)
    }).catch(err=>{
        console.log(err);
        res.status(400).send(err)
    }) */




    }catch(err){
        console.log("error is there")
        res.status(400).send(err)
    }
})
proquibas
@proquibas
image.png
Hi @ankur1163 I tried your code (the first one) and it works as expected.
and from the console.log
image.png
the only difference between my code and yours is that I am using body-parser to catch the req.body data from the request
image.png
Evan Kalvis
@evan17gr
//variables
var getLongitude;
var getLatitude;
var url = "https://fcc-weather-api.glitch.me/api/current?";

//ask for users permission
window.onload = function getUsersPosition(){
    if(navigator.geolocation){
        navigator.geolocation.getCurrentPosition(getLatitudeAndLongtitude);
    }
    else{
        alert("Your browser doesn't support geolocation");
    }
}

//get the user's longtitude and latitude
function getLatitudeAndLongtitude(position){
    var getLatitude = position.coords.latitude;
    console.log(getLatitude);
    var getLongitude = position.coords.longitude;
    console.log(getLongitude);
}

var source = url + "lat=" +getLatitude + "&" + "lon=" + getLongitude;

//new xmlhttprequest to request the JSON file depending on the user's location
var req = new XMLHttpRequest();
req.open("GET", source,true);
req.responseType = "text";
req.onload = function(){
    var resp = JSON.parse(req.responseText);
    console.log(resp);
}
req.send();
can someone please help me
i keep getting this error "Please provide longitude as lon and latitude as lat as numbers/floats"
proquibas
@proquibas
@evan17gr can you share the output of console.log(getLatitude); and console.log(getLongitude); as well as var source = url + "lat=" +getLatitude + "&" + "lon=" + getLongitude;?
Evan Kalvis
@evan17gr
{error: "Please provide longitude as lon and latitude as lat as numbers/floats."}error: "Please provide longitude as lon and latitude as lat as numbers/floats."__proto__: Objectconstructor: ƒ Object()hasOwnProperty: ƒ hasOwnProperty()isPrototypeOf: ƒ isPrototypeOf()propertyIsEnumerable: ƒ propertyIsEnumerable()toLocaleString: ƒ toLocaleString()toString: ƒ toString()valueOf: ƒ valueOf()__defineGetter__: ƒ __defineGetter__()__defineSetter__: ƒ __defineSetter__()__lookupGetter__: ƒ __lookupGetter__()__lookupSetter__: ƒ __lookupSetter__()get __proto__: ƒ __proto__()set __proto__: ƒ __proto__()
main.js:19 52.3555177
main.js:21 -1.1743196999999999
@proquibas
this is the output of the console
but its weird because i can't find anything wrong with it
proquibas
@proquibas
@evan17gr I think it's something wrong with yout "source" string. I try it directly in the browser and it works
image.png
Evan Kalvis
@evan17gr
@proquibas so im confused what am i supposed to change?
proquibas
@proquibas
I mean the "var source = url + "lat=" +getLatitude + "&" + "lon=" + getLongitude;" in your code, maybe it's wrong