express

Page Redirecting issues Node-js

≯℡__Kan透↙ 提交于 2021-02-11 14:48:28
问题 I'm trying to open places.ejs file on clicking the submit button on show.js page, just like the show.ejs page opens on clicking the submit button on new.ejs file, but a reference error is occurring. Please help me fix the error. I'm attaching herewith my routes.js code and a part of my index.js code Any help would be highly appreciable. Thank you routes.js const { con, sessionStore } = require('./config/db'); exports.new = function(req, res){ message = ''; if(req.method == "POST"){ const post

Whats the problem with the socketio connection?

流过昼夜 提交于 2021-02-11 14:45:22
问题 Im having this alot of http petitions ( 6k INSIDE LAGGING ) in 1-3 minutes in the console when i receive or send data to a socketio connection. Im using node+express in the backend and vue on the front Backend: app.js mongoose.connect('mongodb://localhost/app',{useNewUrlParser:true,useFindAndModify:false}) .then(result =>{ const server = app.listen(3000) const io = require('./sockets/socket').init(server) io.on('connection', socket =>{ // console.log('client connected') }) if(result){console

POST http://localhost:3000/api/signup/ 404 (Not Found)

允我心安 提交于 2021-02-11 14:45:08
问题 i am trying to send data of the user from react to express and use the create function to create a new user but is says error 404 and page not found why? my api endpoint (found in client/src/components/api-users : async function create (data) { try { const resp = await fetch('/api/signup/' , { //error initiating here method:'POST', mode:"cors", credentials:'include', headers:{ 'Content-Type': 'application/json ', 'Accept': 'application/json', "Access-Control-Origin": "*" }, body:JSON

Express.js Csurf working in postman but not React.js

自作多情 提交于 2021-02-11 14:41:20
问题 I'm trying to setup CSRF tokens so that I can do a number of checks before issueing a token to the client to use in future requests. Taking the guidance from the csurf documentation, I've setup my express route with the following: const express = require('express'); const router = express.Router({mergeParams: true}); const csurf = require('csurf'); const bodyParser = require('body-parser'); const parseForm = bodyParser.urlencoded({ extended: false }); const ErrorClass = require('../classes

Is there any way of redirecting from one route to another with data from first route to second in node.js?

五迷三道 提交于 2021-02-11 13:41:45
问题 What i want to know is whether is it possible to redirect from one route to another with data from first route to second one? For example from the HTML form i POST the data(say phone number) to a route (say '/route1') and with success operation at this route i want to send phone number to '/route2' from'route1'. If it is possible then how should I do that? 回答1: There are a number of ways to pass data in a redirect. Put the data in a query parameter on the redirect URL http://www.whatever.com

My node js program is giving me a “TypeError: Cannot read property 'then' of undefined”, when reading a json file

荒凉一梦 提交于 2021-02-11 13:41:31
问题 I'm trying to read frpm a json file folder withing my program and i want to use a GET list endpoint to read through browser or postman, but i'm getting the above TypeError. Here is my code: model.js: const fs = require('fs'); function loadTeams() { return new Promise((resolve, reject) => { fs.readFile('./json/prov-nodes.json', (err, data) => { if (err) reject(err); const teams = JSON.parse(data); console.log(teams); resolve(teams); }); }); } app.use(bodyParser.json()); app.get('/list', (req,

Multer parses multipart form data when using postman, but doesn't parse multipart form data in request from client app

旧城冷巷雨未停 提交于 2021-02-11 13:36:53
问题 I'm trying to use multer to support file upload from my react app client to my node/express backend. For some background, I've been using postman 6.7.2, node 8.11.1, express 4.16.3, and multer 1.4.1. After following a tutorial, I could use postman to log req.body and see the entries in the formdata; as in I can log the req.body and the req.file in the route handler () and the file even saves. But when I try sending a request from my react app, the req.body logs as {} and the req.file logs as

How to set multiple views folder in Express.js app

蹲街弑〆低调 提交于 2021-02-11 13:28:48
问题 When I have one views folder specified it will serve files, but when I specify a second alongside it does not work. I have tried numerous things, to no avail. Here is my code: app.use(express.static('views')); //app.set('views', [__dirname + '/views', __dirname + '/views/views2']); app.use("/views", express.static(__dirname + "/views")); app.use("/views2", express.static(__dirname + "/views2")); The app.set doesn't work at all and so I commented it out here, and the last two lines are not

Failed to lookup view “error” in views directory

青春壹個敷衍的年華 提交于 2021-02-11 13:23:59
问题 Failed to lookup view "error" in views directory Here is my code: app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'ejs'); console.log("set views") // uncomment after placing your favicon in /public //app.use(favicon(path.join(__dirname, 'public', 'favicon.ico'))); app.use(logger('dev')); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: false })); app.use(cookieParser()); app.use(express.static(path.join(__dirname, 'public'))); 回答1: You can solve it

sending http request from azure web app to my machine

旧时模样 提交于 2021-02-11 13:22:14
问题 I created an azure web app which send an http request: axios.post('http://*mypublicip*:3000/write/' + Name, { content: data[1] }) meanwhile my computer has a running express server: app.listen(3000, () => console.log(`Server running on port ${port}`)); all my functionality works when I use it locally by sending the request to localhost instead of my ip. I also tried adding host '0.0.0.0' to my app.listen. what am I missing? thanks 回答1: This problem has nothing to do with your webapp . So I