express

Dealing with slash characters in request parameter using Express route

浪子不回头ぞ 提交于 2021-02-18 06:41:27
问题 I'm currently working on a URL shortener app using Express. I want the user to be able to enter a URL like this: https://www.exampleurlshortener.com/new/https://www.google.com The problem is whenever I try to specify the parameter using Express it will only extract the 'https:' section and everything after that is lost because the 2 backslashes are registering as a new route: app.get('/new/:url', (req, res) => { console.log(req.params.url) // outputs 'https:' I thought about specifying each

Dealing with slash characters in request parameter using Express route

旧街凉风 提交于 2021-02-18 06:40:13
问题 I'm currently working on a URL shortener app using Express. I want the user to be able to enter a URL like this: https://www.exampleurlshortener.com/new/https://www.google.com The problem is whenever I try to specify the parameter using Express it will only extract the 'https:' section and everything after that is lost because the 2 backslashes are registering as a new route: app.get('/new/:url', (req, res) => { console.log(req.params.url) // outputs 'https:' I thought about specifying each

Compare passwords BcryptJS

醉酒当歌 提交于 2021-02-17 14:54:44
问题 So I'm trying to build a very basic user login. I'm trying to create a user, then login with those credentials and get back a JSON Web Token. Where I'm stuck is trying to compare the passwords then send a response. Steps: Create User: enter email and password salt/hash user password store user into database return success Login find user by request email value if found compare passwords passwords good send JSON Web Token User Model email:{ type: String, required: true, unique: true },

CORS problem with NodeJS Express and ReactJS

天大地大妈咪最大 提交于 2021-02-17 07:11:13
问题 I have some CORS problem with NodeJS Express and ReactJS. Please help me. Now, I have both frontend( http://locahost:3000 ) and backend( http://locahost:4000 ) using different PORT . The frontend is using 3000 port with ReactJS and the Backend is using 4000 port with NodeJS Express. Frontend API call source code axios.get("/tube/latestted", { headers: { "Content-Type": "application/json", }, }) .then(response => { console.log(response); }); Backend CORS setting source code app.all('/*',

CORS problem with NodeJS Express and ReactJS

ぐ巨炮叔叔 提交于 2021-02-17 07:11:13
问题 I have some CORS problem with NodeJS Express and ReactJS. Please help me. Now, I have both frontend( http://locahost:3000 ) and backend( http://locahost:4000 ) using different PORT . The frontend is using 3000 port with ReactJS and the Backend is using 4000 port with NodeJS Express. Frontend API call source code axios.get("/tube/latestted", { headers: { "Content-Type": "application/json", }, }) .then(response => { console.log(response); }); Backend CORS setting source code app.all('/*',

how to return response to REST api in node js

狂风中的少年 提交于 2021-02-17 05:42:31
问题 I'm new to Node JS. My node js REST api route code is: 'use strict'; module.exports = function(app) { var sequel = require('../controllers/sampleController'); app.get('/task?:email', function(req, res){ res.send(sequel.listByEmail(req.query.email)); }); }; And my listByEmail function is: 'use strict'; var apiKey = '1xxxxxxxxL'; exports.listByEmail = function(emailid) { console.log(emailid); if(emailid != null && emailid != undefined) { var xyz = require("xyz-api")(apiKey); xyz.person

Getting Timeout error while connecting MongoDB Atlas with Mongoose

不羁岁月 提交于 2021-02-17 05:38:42
问题 I am trying to connect to my database on MongoDB Atlas using mongoose. But every time it's giving me the following error: (node:2327) UnhandledPromiseRejectionWarning: Error: queryTxt ETIMEOUT cluster0-abjwg.gcp.mongodb.net at QueryReqWrap.onresolve [as oncomplete] (dns.js:206:19) (node:2327) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled

Node.js - SyntaxError: Unexpected token * when import express

落花浮王杯 提交于 2021-02-16 18:28:08
问题 node: v10.16.3 npm: 6.12.0 I got a error when I import express in node. I'm using this code https://github.com/angular-university/rxjs-course, look at server/server.ts . I run server.ts with $ ts-node ./server/server.ts The related code is: import * as express from 'express'; The error is: import * as express from 'express'; ^ SyntaxError: Unexpected token * at Module._compile (internal/modules/cjs/loader.js:723:23) at Module.m._compile (/usr/local/lib/node_modules/ts-node/src/index.ts:493:23

TypeError: res.sendFile is not a function

痴心易碎 提交于 2021-02-16 18:00:19
问题 I am working through a basic MEAN tutorial, and I am already hitting a wall. Getting 'TypeError: res.sendFile is not a function' error //package.json { "name": "http-server", "main": "server.js", "dependencies": { "express": "^4.13.4" } } //server.js var express = require('express'); var app = express(); var path = require('path'); app.get('/', function (res, req) { res.sendFile(path.join(__dirname + '/index.html')); }); app.listen(1337); console.log('Visit me at http://localhost:1337'); 回答1:

TypeError: res.sendFile is not a function

ぃ、小莉子 提交于 2021-02-16 18:00:09
问题 I am working through a basic MEAN tutorial, and I am already hitting a wall. Getting 'TypeError: res.sendFile is not a function' error //package.json { "name": "http-server", "main": "server.js", "dependencies": { "express": "^4.13.4" } } //server.js var express = require('express'); var app = express(); var path = require('path'); app.get('/', function (res, req) { res.sendFile(path.join(__dirname + '/index.html')); }); app.listen(1337); console.log('Visit me at http://localhost:1337'); 回答1: