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
Ankur sharma
@ankur1163
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
Evan Kalvis
@evan17gr
i dont see what could be wrong with it though tbh @proquibas
proquibas
@proquibas
@evan17gr honestly I don't know where is the problem, check it https://repl.it/@jtejedera/CriticalFortunateQuadrant
Evan Kalvis
@evan17gr
that's so weird
thanks for the help @proquibas
proquibas
@proquibas
I think that is something about the format of the "source" string, the error message is about the lat/lon format
Evan Kalvis
@evan17gr
@proquibas i ve tried changing the format
like putting lon first and then lat
but still the same thing
proquibas
@proquibas
did you tried to hardcode the values in the "source" string?
Evan Kalvis
@evan17gr
just to test whether the coordinates are working?
proquibas
@proquibas
yes
like I did in the repl.it
try to know the type of the values given in the getUserPosition function using console.log(typeof getLatitude);
Evan Kalvis
@evan17gr
image.png
i tried to hard code it and the same error
@proquibas
proquibas
@proquibas

@evan17gr try this one:
//variables
var getLongtitude;
var getLatitude;
var api;
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){
getLatitude = position.coords.latitude;
getLongtitude = position.coords.longitude;
api = url + "lat=" +getLatitude + "&" + "lon=" + getLongtitude;
getObjs();
}

//new xmlhttprequest
function getObjs(){
var req = new XMLHttpRequest();
req.open("GET", api,true);
req.onload = function(){
const getText = JSON.parse(req.responseText);
console.log(getText);
}
req.send();
}