express

Application Error when attempting to deploy Node.js/Express/Socket.io application on Heroku

我的梦境 提交于 2020-01-22 05:51:06
问题 I am fairly new to all of these technologies (including somewhat JavaScript) so you might have to bear with me here. I followed the ChatApp tutorial over at Socket.IO docs fairly closely and modified the application to my likings somewhat; however, I don't think I changed much on the side of server interaction and stuff. My problem is no matter what I do, I can't seem to be able to get my application to successfully run on Heroku. I get this error message when trying to load the app:

nodemon not working properly

不羁岁月 提交于 2020-01-22 05:15:06
问题 I am running my nodejs app by npm start I just installed nodemon by sudo npm install -g nodemon so that i can get my server restarted when i save changes to files. But when i try to start the server, something like this nodemon ./app.js localhost 3000 or nodemon start localhost 3000 I get this as output LM-SJC-00871929:webapp gdeep$ nodemon ./app.js localhost 3000 28 May 23:34:30 - [nodemon] v1.1.1 28 May 23:34:30 - [nodemon] to restart at any time, enter `rs` 28 May 23:34:30 - [nodemon]

Node.js and Express session handling - Back button problem

拈花ヽ惹草 提交于 2020-01-22 04:28:07
问题 I have a restricted area '/dashboard' in my Express application. I use a very small function to limit the access: app.get('/dashboard', loadUser, function(req, res){ res.render('dashboard', { username: req.session.username }); }); function loadUser(req, res, next){ if (req.session.auth) { next(); } else { res.redirect('/login'); } }; The problem is that when I logout a user by calling... app.get('/logout', function(req, res){ if (req.session) { req.session.auth = null; res.clearCookie('auth')

NodeJS error help: empty object req.params.id

怎甘沉沦 提交于 2020-01-22 04:03:24
问题 I am getting an error on my program - any insight would be appreciated thanks. Cannot read property '_id' of undefined at eval (eval at compile (C:\Users\Adama Sawadogo\node_modules\ejs\lib\ejs.js:626:12), <anonymous>:13:34) at responses (C:\Users\Adama Sawadogo\node_modules\ejs\lib\ejs.js:656:17) at tryHandleCache (C:\Users\Adama Sawadogo\node_modules\ejs\lib\ejs.js:254:36) at View.exports.renderFile [as engine] (C:\Users\Adama Sawadogo\node_modules\ejs\lib\ejs.js:459:10) at View.render (C:

Undefined args on a mutation, using apollo-server

南楼画角 提交于 2020-01-22 03:27:04
问题 Im working with apollo-server, everything works as expetected but the mutation arguments are undefined when the mutation is called from the frontend. const express = require('express'); const morgan = require('morgan'); const { ApolloServer, gql } = require('apollo-server-express'); const mongoose = require('mongoose'); require('dotenv').config(); const app = express(); const typeDefs = gql` type msgFields { email: String! textarea: String! createdAt: String! } input MsgFieldsInput { email:

Websockets token authentication using middleware and express in node.js

房东的猫 提交于 2020-01-22 02:30:32
问题 I use node.js, express and express-ws that is based on ws Express-ws allows to create express-like endpoints for websockets. I am looking for a solution to authenticate users in websocket connections, based on a token. Since my ws server is based on an HTTP one const wsHttpServer = http.createServer(); wsHttpServer.listen(5001); const expressWs = require('express-ws')(app , wsHttpServer); and since the ws connection is based on an HTTP one that gets upgraded to a ws, WHY I cannot pass a token

Update subset of fields with Mongoose

本小妞迷上赌 提交于 2020-01-22 02:29:06
问题 How can I update a MongoDB document with Mongoose when only a subset of its fields are specified? (i.e. update the specified fields, but leave any other existing fields unchanged) In the following route handler, the user can choose which fields to provide. The following works, but using the if statements does not feel particularly great. Is there a more elegant solution? // Get the user properties from the request body const { email, firstname, lastname} = req.body; // Decide what fields to

How do I use Postgres function in my NodeJS Express App?

孤者浪人 提交于 2020-01-22 02:22:14
问题 I am new to Postgres database but I have choosing it for a project I am working on. I would like to add data to two tables in Postgres with one query using server-side function. After a user submit data from a form in the frontend for table2, I want my SQL query to insert id, value1 in table1. Then the same id in table one will be used to create data of table2 which will store the submitted datas. I got the code below (courtesy @ErwinBrandstetter) to create a server-side function to take

Express body-parser handling checkbox arrays on forms

こ雲淡風輕ζ 提交于 2020-01-21 12:19:10
问题 I have an HTML form with an array of checkboxes (using [] naming). I need to be able to process this with express . I'm using body-parser . The problem is that unchecked checkboxes don't submit a value, and at the same time, body-parser seems to remove "holes" in arrays by simply packing the values into an array in order of indices, but ignoring the indices themselves. (Update: Actually it looks like qs is the culprit). Consider this full example, which displays a form and responds with a

nodejs express app deploying to production

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-21 12:07:37
问题 Sorry if this is a basic question, I am still wrapping my head around nodejs deployments. I have an app written on nodejs which I want to deploy to production. So far for testing purposes I have used Express. However from what I know Express is a dev server and not a production server. How do I deploy the nodejs app to production and what is the server I should use. Plus I have a lot of code written for express like routes and middleware, how does this work when I deploy to another server?