express

displaying collection data from mongodb using axios in reactjs

你离开我真会死。 提交于 2021-01-28 15:11:26
问题 I am new to MERN and I try to display data from mongodb collection using axios. I try to display a list of cities on the web page. I am not sure if I am doing it write. Should I use super state?jsonpostman Here is my reactjs code: import React, { Component } from 'react'; import axios from 'axios'; export class Cities extends Component { constaractor(state) { state = { locations:[] }; } componentDidMount() { axios.get('/cities') .then(cities => console.log(cities.data)) .catch(e => console

displaying collection data from mongodb using axios in reactjs

痴心易碎 提交于 2021-01-28 15:11:03
问题 I am new to MERN and I try to display data from mongodb collection using axios. I try to display a list of cities on the web page. I am not sure if I am doing it write. Should I use super state?jsonpostman Here is my reactjs code: import React, { Component } from 'react'; import axios from 'axios'; export class Cities extends Component { constaractor(state) { state = { locations:[] }; } componentDidMount() { axios.get('/cities') .then(cities => console.log(cities.data)) .catch(e => console

displaying collection data from mongodb using axios in reactjs

a 夏天 提交于 2021-01-28 15:09:49
问题 I am new to MERN and I try to display data from mongodb collection using axios. I try to display a list of cities on the web page. I am not sure if I am doing it write. Should I use super state?jsonpostman Here is my reactjs code: import React, { Component } from 'react'; import axios from 'axios'; export class Cities extends Component { constaractor(state) { state = { locations:[] }; } componentDidMount() { axios.get('/cities') .then(cities => console.log(cities.data)) .catch(e => console

Getting 404 (Not Found) on axios.delete()

孤者浪人 提交于 2021-01-28 14:17:45
问题 I'm trying to implement the delete functionality for my survey creation app. I'm using MongoDB with mongoose for the database, node.js/Express for the backend server and React/Redux for the frontend side. Although I think I set routing correctly, I get 404 (Not Found) on axios.delete(). The error says that http://localhost:3000/api/surveys/delete/{the-survey-id-here} is not found. I have been reading the documentation of axios, Express, mongoose and other websites, however, nothing worked for

Navigator undefined in ejs file express

会有一股神秘感。 提交于 2021-01-28 14:10:59
问题 I want to get the latitude and longitude of the user's location. In the ejs file I am getting error navigator undefined.Can somebody please help?Thanks in advance. <%if ('geolocation' in navigator) { console.log("geolocation supported"); } %> <%else { console.log("Geolocation is not supported by this browser."); }%> Updated code: <html> <head> <meta charset="utf-8"> <title>Daily Journal</title> <meta charset="utf-8"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7

Send image path from node.js express server to react client

梦想的初衷 提交于 2021-01-28 14:10:04
问题 I want to build api that store images and send them to react client app. The images are located in the express app in the public/images folder. I want to send the data obj to the client with the image path inside. Express.js: var express = require('express'); var path = require('path'); var favicon = require('serve-favicon'); var logger = require('morgan'); var cookieParser = require('cookie-parser'); var bodyParser = require('body-parser'); var cors = require('cors'); var index = require('.

How can I receive data that was sent by express on functional component?

╄→гoц情女王★ 提交于 2021-01-28 13:33:42
问题 function Header(props) { const [ serverData, setServerData ] = useState({}); fetch('http://localhost:4001/api') .then(res => res.json()) .then((data) => { setServerData(data); console.log(data); }); return ( <div>{serverData}</div> ); } I'm trying to make this functional React component to get data from express api. My code editor keep shutting down, I think that receiving data part is in the loop. How can I make this functional component to fetch the data just once, without using

Cordova and express js?

浪子不回头ぞ 提交于 2021-01-28 12:48:59
问题 I am really lost when it comes to rendering express views onto the client, when the client is a cordova app. There are a few obvious things, for example the app would need to make a GET request and the express app would render the view. I'm not sure how to do that though, how does one make those requests? In the emulator I tried alert(window.location.pathname) and it shows android_asset/www/index.html so that needs to be adjusted right? 回答1: Use AJAX to make calls from your application to

Send pdf via express to js client and download

 ̄綄美尐妖づ 提交于 2021-01-28 12:20:12
问题 I am trying to send pdf file from my express server using the client when requested like this: res.setHeader('Content-Type', 'application/pdf'); res.setHeader('Content-Disposition', 'attachment; filename=test.pdf'); fs.createReadStream('test.pdf').pipe(res); And then on the client side I am trying to download it by taking the resulting string converting it to a url and downloading from there. var blob = new Blob[pdfString], { type: 'application/pdf' }); var url = window.URL; var downloadUrl =

Cannot GET - Error After refresh using Ionic

喜夏-厌秋 提交于 2021-01-28 12:14:05
问题 I'm using Ionic framework to build a hybrid mobile application and I have html5Mode set to true, Ui-Router, and gulp to provide me with livereload, sass compiling, css and javascript minifying. The problem is whenever I navigate to a state directly from the index, everything works fine, requests are being made to my server, but when I refresh that same state, I get Cannot GET error. I am treating my Ionic application as a separate thing from my Express.JS app. Here's some code: States