express

Node.js: What's a good way to automatically restart a node server that's not responding?

[亡魂溺海] 提交于 2020-04-29 09:55:18
问题 I've inherited a node.js/Express app that is a bit of a mess. It's regularly and fairly randomly getting stuck and not responding to any request until it is restarted. I suspect that something within the app is blocking and either getting stuck in a loop or making a request to an external api without using proper Async techniques, and never getting a response and never timing out at witch point the server just stops responding but doesn't crash. I would obviously like to find the culprit code

assigning “exports” to a function in nodejs module doesn't work

て烟熏妆下的殇ゞ 提交于 2020-04-21 16:30:54
问题 in one file (otherFile.js) I have this: exports = function() {} in my main file I have this: var thing = require('./otherFile.js'); new thing(); however this gives me the following error: TypeError: object is not a function and if in otherFile.js I have this instead: exports.myFunction = function() {} and in my main file I have this: var thing = require('./otherFile.js'); new thing.myFunction(); then it works perfectly. Why is it that I'm not allowed to assign a function to the exports

assigning “exports” to a function in nodejs module doesn't work

社会主义新天地 提交于 2020-04-21 16:28:13
问题 in one file (otherFile.js) I have this: exports = function() {} in my main file I have this: var thing = require('./otherFile.js'); new thing(); however this gives me the following error: TypeError: object is not a function and if in otherFile.js I have this instead: exports.myFunction = function() {} and in my main file I have this: var thing = require('./otherFile.js'); new thing.myFunction(); then it works perfectly. Why is it that I'm not allowed to assign a function to the exports

“media type unrecognized” when uploading an image to Twitter using npm twit

这一生的挚爱 提交于 2020-04-18 06:32:32
问题 I am working on an express node app that posts to twitter when a user inputs an image into a form. I am saving the image locally before uploading, which works. After I encode the file to base64, I try to upload the base64-encoded file to Twitter using twit's media/upload feature. When I do this, I get an error saying "media type unrecognized." Here is my code: app.post('/tweet', function(req, res){ var time = new Date().getTime() let image = req.files.image var imgpath = './images/img' + time

“media type unrecognized” when uploading an image to Twitter using npm twit

▼魔方 西西 提交于 2020-04-18 06:31:09
问题 I am working on an express node app that posts to twitter when a user inputs an image into a form. I am saving the image locally before uploading, which works. After I encode the file to base64, I try to upload the base64-encoded file to Twitter using twit's media/upload feature. When I do this, I get an error saying "media type unrecognized." Here is my code: app.post('/tweet', function(req, res){ var time = new Date().getTime() let image = req.files.image var imgpath = './images/img' + time

I am trying to get readable date from firestore

 ̄綄美尐妖づ 提交于 2020-04-18 06:26:08
问题 I am trying to get readable date from Timestamp data type in my firestore database. for (var ticketDoc of ticketsSnapshot.docs) { var timeStamp = await ticketDoc.data().TimePreferred; console.log(timeStamp.toDate()); var time = new Date(timeStamp).toDate(); ticketDoc.data().TimePreferred = time; tickets.push(ticketDoc.data()); } I read the question about a similar problem at : How do I convert a Firestore date/Timestamp to a JS Date()? so, i tried to do same and i expect the output of

Get data from different model nodejs mongodb express js

▼魔方 西西 提交于 2020-04-18 06:24:23
问题 I have two model files Bank Deposits and Sub account details. From Sub account details I want to get current balance to Bank deposits . I want to do this in mongodb and node js. I am currently aggreagate lookup operation but it is showing the array as empty. BankdepositModel.js var mongoose = require("mongoose"); var BankDepositsSchema = new mongoose.Schema( { source_sub_account: Array, amount: Number, cheque_notes: Number, to_bank_account: Array, amount_in_words: String, bank_Ref_no: String

Can React-Router point directly to a route defined with Express instead of rendering a component?

北城余情 提交于 2020-04-18 05:45:32
问题 How I can use React-Router to point directly to a route defined with Express on the backend instead of rendering a component? I want to return valid JSON with no HTML included in the response. 回答1: React-Router only handles routing on the React frontend. There is no way for React-Router to point to an Express Route on the back end. A React component would have to use that API endpoint. Why not just hit the endpoint manually. 来源: https://stackoverflow.com/questions/61162675/can-react-router

req.body is an empty object from simple HTML form using express

爷,独闯天下 提交于 2020-04-18 05:40:46
问题 I'm getting a req.body back when I submit my HTML form, but it's always an empty object. I'm testing in postman and also submitting the form from the localhost in the browser. When I log it in the node console, it says [Object: null prototype] I've read and tried all the (many) proposed solutions to similar things, but none seem to apply. Thank you very much! // homepage.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width,

Convert Oracle query output to json (Oracle / NodeJS)

孤街醉人 提交于 2020-04-18 05:35:13
问题 I'm doing an app with React / Express (NodeJS) / Oracle, I have an Express route that gets datas from an Oracle table, Here's a part of the code in the route : let conn; try { conn = await oracledb.getConnection(config); const result = await conn.execute("select JSON_OBJECT ('departement' VALUE departement, 'ufh' VALUE ufh, 'libelle' VALUE libelle, 'nomhopital' VALUE nomhopital, 'typeservice' VALUE typeservice, 'actif' VALUE actif) from Z_SOUPAP2CARTESITE where actif=1"); res.send(result.rows