Newest express Questions

Q&A for professional and enthusiast programmers

How to require from required file?

I need to require bar from bar.js and foo from foo.js in each file. How I can do it? foo.js const bar = require('./bar'); const foo = 'Hello'; console.log(`${foo} ${bar}!`); module.exports = foo; ...

javascript switch statement unexpected token in node.js

below is my route.js, what's wrong with my switch statement? router.post('/api/profile?:id?:action', (req, res) => { switch(req.query.action) { case "approve" : { return res.json({req....

Stylus Error Reporting When Used As Express Middleware

I have used express-generator to roll an app with Stylus express --view=pug --css=stylus appdir , want to know if there's a way to surface Stylus' error reporting when running the application (npm ...

How to call server side function from html button (not in a form) using ExpressJS

I have an express app with an index.js that has the following: <form method="post" action="searchAll"> <input type="text" name="keyword"/> <button type="submit">Submit</...

AWS S3 public bucket hosting static webpage behind a proxy

I’m trying to access some webpages available using S3, and it works fine using an url like the following: http://my-crazy-bucket.s3-website-us-east-1.amazonaws.com Thing is.. I need to hide those ...

Express multiple static route regex parsing

I'm trying to serve up static files from two directories using express. The reason I'm serving from two directories is due to naming collisions between the files being served in directory #1 having a ...

How to send json data with file in same response using express,node,mongodb?

I upload files using multer and gridfs storage and everything is working fine .after uploading file i saved my userdetails with filepath in user collection. Now i want to retrieve userdata from user ...

Unable to process same GET request multiple times. How do I get around this?

I'm making a Node.JS app where the user sends commands to a robot. These requests are received from Angular.JS $http.get() requests. This is what the code looks like server side: app.get('/control/:...

Authentication on node js and express js 2

I have built login page authentication using passport local strategy. Part of the code in users.js goes here which is successful.. router.post('/login', passport.authenticate('local', {...

How to create module for express-mailer?

I need to create module for this code, please help to change for express.js module? I use basic express-generator. mailer.extend(app, { from: 'mail@mail.com', host: 'smtp.gmail.com', ...

Fetching data from express webapp for chart.js

I'm very new to node.js and javascript and need some help with chart.js. I have a .html file containing code for my chart but the data needs to be in the form of lists. I have an Express server ...

ExpressJS + AngularJS: communicate routes and controllers

I have a json object in my express.js routes file and in order to parse it, I am guessing that the best way would be to send to my Angular controller to be looped in my view. routes/myaccount.js ...

Obtaining letsenrypt certificate with Node.js+Express.js

We cannot stop out production server to renew Let's Encrypt certificate (but we can restart it with a near zero downtime to load the new certificate). Can we configure express.js routing to get ...

Updating Twilio MediaUrl for use with Express 4

I am updating my twilio sms messaging tool to use express 4. On one one line of code I am having an issue. var mediaUrl = request.param('MediaUrl' + i); //deprecated in express 4 When I attempt to ...

Building an inbox system using Express/MongoDB

I have been developing an app for renting flats for a personal project of mine. I have been wondering about how to build/implement an inbox system to the current app which uses mongodb as database. ...

ExpresJS is redirecting after POST

I have following problem. My server which is writen in ExpresJs ( used MongoDB as database ) is redirecting my page after registration ( POST method ). Actually, i don't know why.. Can you please help ...

HTTP to HTTPS redirection in Node and Angular 2 App

I have an app which runs on 80 and 443 port. When user hit http version application, it should get redirected to HTTPS. I have tried the below code to do this. function handleRedirects(req, res, next)...

Mongoose - Modle.update() updates wrong document - Cast Error

I need some help to clear some things up. I have a Model: var Event = new Schema({ event_code: String , segments: [Segment] }); The creation of new documents work very well like perfect. When ...

Socket.io stops working on handshake after 100+ users

I have a site which, when less than ~100 people are on it, works fine. But after that point, I often get an error saying: WebSocket connection to ' failed: Error during WebSocket handshake: ...

How to protect one admin page with react-router-dom v4?

I'm creating a website with different pages. It uses React.js in the front-end and Express in the back-end. Basically it is a MERN-stack. For navigation i use react-router-dom v4. Routing works like ...

Mongo DB not updating, without error

Trying to update the below M Lab hosted mongo DB, not much luck, any ideas? Form input via handlebars template, routed to express server. No errors, and DB does not update. { "_id": { "$...

Angular data binding within components not working when using jade

I am using angular 1.6.4 and node 6.1 and I am trying to load a simple array that I have specified in the player-main component to the template but it does not get loaded correctly. angular. module('...

Error: Can't set headers after they are sent. comes from calling the smart contract function

I wrote a smart contract for creating simple database. It contains multiple functions , when i hit an REST api first time it gives me correct output but at further hits it make node server crash with ...

Cookies on chrome localhost with aws beanstalk backend, express-session

There are a lot of question and informations about this, I tried to fit to my situation but it didn't work. The cookie is correctly sent back and forth but can't seem to be accepted in chrome. Since ...

How to generate an image in nodejs and sent it to fontend?

fontend: var img = new Image(); img.onload = function() { console.log('done'); }; img.onerror = function() { console.log('error'); // trigger }; img.src = 'http://localhost: 3000?test.gif'; ...

Can't set headers

I have some basic authentication in a route that when used is throwing a console error. Error: Can't set headers after they are sent. at ServerResponse.OutgoingMessage.setHeader (_http_outgoing....

How do I update json data in postgres sql in nodejs?

my data structure schema is like users( id serial primary key, data json ); I want to update data key. I'm using node-postgres library and So far I have tried something like this: pg....

express PUT shows cannot PUT error

I have this in my express router.put('/admin/profile?:id/actions', (req, res) => { console.log(req.body.actions) }); and in postman I do a PUT request http://localhost:3000/api/admin/...

redirect to backbone js file using node js

<form class="f" method="POST" action="/backtoNode"> 1.in app.js file server.post('/backtoNode', (request, responce)=>{ responce.render('page'); }); 2. in router.js module....

Instagram API in Express

I can't make an API call to instagram with Express and below is my code that I followed online, but still failed =[ Am I missing something? var express = require('express'); var instagram = ...

Can I use Angular to retreive data from Mongodb?

I'm trying to get data from my MongoDB displayed in my HTML page. Is it possible to get this done by Angular or do I need a templating engine for this? I'm using Express on Node platform. I've ...

A standard for error handling and graceful shutdown of Node/Express server

The more I read about all the issues with how to start a node/express server and handle errors and shutdown properly, the more I get confused. Below is the basic script I usually use. I would like ...

Can't get Express @types working

I'm trying to get the Express @types working but without any success. I'm using Visual Studio Code and I'd really love to have the autocompletition working. So far I've seen that installing the @types ...

$http post with angular gives error: possibly unhandled rejection

I've just managed to get my $http post working over Angular. It does what it needs to do, but when I post the data and then refresh the page it gives this error in my console: Possibly unhandled ...

using common layout for all the pages in pug

I am trying out pug with express views/layout.pug doctype html html head title= title link(rel="shortcut icon", href="favicon.ico", type="image/x-icon") link(rel='stylesheet', href='/...

Create MySql schema in the model in express application

I am using express-MVC-generator for creating app skeleton in node js and once I have my project structured, I need to change default database in mongo for a MySQL database but I can´t find how to ...

Nesting MongoDB Schema

I've been learning MongoDB from their online Webinar hosted on their website and I'm trying to link Products to a Category (eg. iPhone belongs to Category Mobiles which has ancestors such as ...

Heroku is giving me a 503 when trying to open my web app, works on local host

I am trying to deploy to heroku but get a 503 even though it runs on localhost. I am curious as to if my server is set up correctly as I am newer to programming. I hope anyone can point me in the ...

How to return multiple Mongodb Collections in one app.get request?

I need to load two sets of data from two different mongodb collections onto one page. My route page that makes the request through mongoose looks like this app.get('/testPage', function(req,res){ ...

Difference between adding route keyword in defining route in Express

What is the difference between router.route('/create') .post(validate(hotelValidation.createHotel), function (req, res) { and simply router.post('/create', validate(hotelValidation.createHotel)...

.gql or .graphql file types with Node

I'm using Apollo's graphql-server-express with Node and I would like to turn my "typedef" schema definition files into .graphql or .gql files for clarity and syntax highlighting. What is the best way ...

Using Services and Controllers in a Node.js-Express.js-Mongoose app

I am new to Express.js app dev. I need to add users to Mongodb and later Delete and Update them too. The Add part works fine, however, i am stuck with Delete (and later shall work on update too). ...

PassportJS Access-Control-Allow-Headers when making Express redirect

I'm receiving the following error: XMLHttpRequest cannot load http://localhost:4200/#/partners. Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight ...

Express and compression

Is there any reason to use https://www.npmjs.com/package/compression module while using nginx proxy with gzip compression turned on?

express-cassandra does not work in npm test

I am a noob in node js and express-cassandra I have a very simple helloworld app written according to the getting started guides of express js and express-cassandra The app is built by express 4.15....

GraphQL with Keystone wants field type must be Output Type but got: undefined

I wan't to make GraphQL endpoint for my keystone.js app (via express middleware express-graphql). Here is my Keystone Schema: const keystone = require('keystone'); const Types = keystone.Field....

How to restrict API's to run only in the browser?

I am using node js and i put polices to restrict the api's accurance otherthan in browser.For that i put the following condition app.route('/students').all(policy.checkHeader).get(courses.list) ...

mongoose update but still gotten old data result returned [duplicate]

User.findOneAndUpdate({_id: req.query.id}, {status:'approved'}, {upsert: true}, (err, response) => { if(err) { return res.json({err}) } return res.json({response}); }); The data ...

Stormpath information for login

I've been trying to find needed info to get my stormpath api to work so i would have a very basic login funtion to access my app, i've gotten it to work once before in another project but the problem ...

Multiple facebook/twitter login express nodejs

Is it possible to connect with multiple facebook, twitter account against a single user in nodejs express through passport or anything else? and even post status from there?
Translating... 0%