express

Can I use a file based database on Heroku?

会有一股神秘感。 提交于 2021-01-30 09:09:06
问题 I have a small Node.js / Express app deployed to Heroku. I'd like to use a lightweight database like NeDB to persist some data. Is it possible to periodically backup / copy a file from Heroku if I used this approach? 回答1: File-based databases aren't a good fit for Heroku due to its ephemeral filesystem (bold added): Each dyno gets its own ephemeral filesystem, with a fresh copy of the most recently deployed code. During the dyno’s lifetime its running processes can use the filesystem as a

Can I use a file based database on Heroku?

旧时模样 提交于 2021-01-30 09:06:06
问题 I have a small Node.js / Express app deployed to Heroku. I'd like to use a lightweight database like NeDB to persist some data. Is it possible to periodically backup / copy a file from Heroku if I used this approach? 回答1: File-based databases aren't a good fit for Heroku due to its ephemeral filesystem (bold added): Each dyno gets its own ephemeral filesystem, with a fresh copy of the most recently deployed code. During the dyno’s lifetime its running processes can use the filesystem as a

Passportjs - req.logout function does not exist

早过忘川 提交于 2021-01-29 21:55:35
问题 I have a route that looks like so: exports.logout = function(res, req){ req.logout() // I blow up res.redirect('/') } Error: Object #ServerResponse has no method 'logout' The Request object does not contain a logout function when this route is called. I assume that this is because I have my middleware in the wrong order. Is that correct? This is what my configuration looks like: app.use(express.methodOverride()); app.use(express.static(path.join(__dirname, 'public'))); app.use(express

Proper usage of Express' res.render() and res.redirect()

天涯浪子 提交于 2021-01-29 21:49:03
问题 I am using a res.redirect('page.ejs'); and on my browser I get the message: Cannot GET /page.ejs I have not declared this in my routes file in the style of : app.get('/page', function(req, res) { res.render('page.ejs'); }); Should this be included in order for the res.redirect() to work? When I do not use res.redirect() but res.render() , even if I have not the app.get() code, it still works. 回答1: so to understand this, let's look at what each of these methods do. res.redirect('page.ejs');

Anyway to unzip a file uploaded in memory using Multer?

青春壹個敷衍的年華 提交于 2021-01-29 20:23:15
问题 I am using Multer to take a file uploaded on a form and keep it in memory so that I can parse it and spit out some stuff, but is there a way I can take in a zip file and be able to unzip it and still keep the unzipped files in memory without writing to a disk? I know there is an npm module for node called 'unzip', but it seems to only be able to pull a file from a physical location, unless I am mistaken. I appreciate any insight! const multer = require('multer'); const storage = multer

How to validate dynamic field data on the react client-side and node server-side?

寵の児 提交于 2021-01-29 19:54:30
问题 I have created dynamic input field in the React component, but don't know how to validate this dynamic field data on the client-side when onChange and onSubmit event occurred. I usually use joi or yup to validate data, but don't know how I can validate dynamic field data. Here is my code: import React, { useState } from 'react'; import { v4 as uuidV4 } from 'uuid'; import './styles.css'; const createFieldsObject = (fields) => ({ id: uuidV4(), fields, }); const DynamicTable = ({ fields }) => {

How can I improve error handling on a pool

孤街醉人 提交于 2021-01-29 18:45:37
问题 I am have created a class User that will hold the logic for inserting a new user into a postresql database. My code works perfectly but i think it is poorly written and would like some views on how to improve it, especially error handling. const pool = require('../config/config.js'); // user constructor class User { constructor(user) { this.username = user.username; this.email = user.email; this.password = user.password; this.role = user.role; } // save new user in databes createUser(res) {

How should I format my POST data for testing an express API endpoint?

安稳与你 提交于 2021-01-29 18:20:43
问题 I am following: https://www.digitalocean.com/community/tutorials/getting-started-with-the-mern-stack. I would like to test an API endpoint built using express. I would like to test POST. The node server is running and I am using postman to check if the endpoint is working. I am unclear on how to format the post data and my POST requests result in errors when I send them. My API is below: const express = require ('express'); const router = express.Router(); const Todo = require('../models/todo

how to store req.body.state in nodejs

独自空忆成欢 提交于 2021-01-29 17:19:30
问题 This is the backend section of the server in node js stub.PostWorkflowResults( { workflow_id: "Demographics", inputs: [ {data: {//need req.body.input here //}} ] }, metadata, (err, response) => { if(response){ console.log(response) }else { console.log(err) } I used bodyparser. What needed is to put req.body.input inside the object {data: {//need req.body.input here //}} 回答1: FrontEnd //App.js import axios from 'axios' import {useEffect, useState} from 'react' import './App.css'; function App(

JavaScript onclick event gets the wrong id from dynamically generated html element

别说谁变了你拦得住时间么 提交于 2021-01-29 16:26:57
问题 Using mongodb and ejs in a NodeJS application, I have created a function that loops through products in the shopping cart and dynamically shows each one of them on the page, inside a table. I am trying to create a quantity update function that uses an input field to take the quantity and a button to update the database. My HTML: <tbody class="product-container"> <!-- loop through each product --> <% products.forEach (function(element) { %> <tr valign="top" class="cart-p-list"> <!-- get