Error: The variable 'err' is not declared in this scope.at line app.post

Tools I am Using

Situation Description

I attempted to make a post request using Postman for testing purposes, but it is not working (Get requests are working fine). Does anyone know what might be causing this error? I have tried the test multiple times but the post function is not functioning correctly.

Console Output in Visual Studio

 functions: Finished "api" in ~1s
>  (node:28624) UnhandledPromiseRejectionWarning: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
...
(Truncated for brevity)

Desired Outcome

I want to successfully create a data entry in Firestore by posting from Postman.

Index.js Code Snippet

const functions = require('firebase-functions');

// Firebase Admin SDK
const admin = require('firebase-admin');
admin.initializeApp();

const express = require('express');
const app = express();

app.get('/screams', (req, res) => {
...
});

exports.api = functions.https.onRequest(app);

app.post('/scream',(req, res) => {
...
});

My Cloud Firestore Database Snapshot

https://i.stack.imgur.com/RRWO1.png

Postman Test Screenshot

https://i.stack.imgur.com/u0irW.png

Answer №1

I was able to resolve the issue, however, I am unsure of why it occurred in the first place.

Recommended Solution:

  1. Try deleting the Firestore database and creating a new one

  2. Deploy Firebase again

  3. Serve Firebase

  4. Retest using Postman

  5. If everything is working as expected, then the issue has been resolved successfully

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for creating a Vue component that triggers the select dropdown to open when the entire div or wrapper is clicked

I have a custom-designed select dropdown with unique symbols for the select arrow. To achieve this look, I've hidden the default select arrow/triangle and placed our symbol on top as an image file. <div class="select-wrapper"> < ...

Error message: The login buttons from Meteor's accounts-ui-bootstrap-3 are not showing up on the webpage

Following the installation of bootstrap-3 and accounts-ui-bootstrap-3, the expected ui-accounts login widget was not displayed when using {{ loginButtons }}. Instead, a <div> appeared in place of the widget, with no actual widget visible. Are there ...

What is the best method to implement a loading spinner within a React and Node application while using Nodemailer?

Is it possible to implement a functionality where clicking the Send button triggers a spinner next to the button, followed by changing the button text to "Message Sent"? I managed to change the button text, but there is no loading time, it happens instantl ...

Data vanished from the input field values

Having an issue with displaying an HTML table inside a .cshtml file. When I hardcode values, the table appears as expected. However, when I attempt to populate it using a foreach loop, the table disappears. <script> var nTable = ""; $(docu ...

Preventing jQuery Validate Plugin from Validating on Blur Events for a Custom Feature

How can I prevent jQuery validate from validating the form on blur events? I have a form with three pairs of start/end dates, each using DatePicker. Each pair should validate if the other field is filled because both are required for form submission. Howe ...

Would combining node.js with express for the back-end and emberjs for the client side be a suitable choice for my project?

As a seasoned web developer, I have limited experience with nodejs and have yet to dive into the world of emberjs (although I have worked extensively with backbone). I am embarking on a new project to create a web-based writing application focused on lite ...

Is it possible for me to retrieve/load a <datalist> element from a different file?

I'm in the process of developing a Google Chrome extension that essentially consists of a dropdown menu and an input box with datalists. The user can change their selection in the dropdown menu, which will then switch the datalist being used by the in ...

Unable to get Express router post function to properly function

Issue: var express = require('express'); var router = express.Router(); Route.js: Setting up Post route router.route('/signup') .post(function (req, res) { console.log('post signup called', req.body); re ...

"By implementing an event listener, we ensure that the same action cannot be

function addEventListenerToElement(element, event, handlerFunction) { if(element.addEventListener) { element.addEventListener(event, function(){ handlerFunction(this.getAttribute("src")); }, false); } } //initialize the function addEve ...

Using CSS to Create Text Wrapping

I have a massive string of randomly generated numbers that I am trying to display in a div block. Since the string is quite long, it's currently being shown in one single line. For instance: String str="13,7,5,1,10,7,18,11,17,10,9,16,17,9,6,19,6,13, ...

Error: Morris.js is unable to access the property 'x' because it is undefined

Seeking assistance in utilizing Morris.js to create an area chart using data from a JSON file. The JSON data is as follows: [{"period": 0, "time": 121.0}, {"period": 1, "time": 102.0}, {"period": 2, "time": 104.0}, {"period": 3, "time": 91.0}, {"period": ...

Could anyone clarify the reason behind the success of one function while the failure of the other?

Currently delving into the world of React, I decided to follow along with the Road To React book. In this guide, the author presented this code const List = (props) => ( props.list.map(item => ( <div key={item.objectID}> & ...

Looking to restrict the data retrieved from an API while utilizing ReactJS

I am currently fetching transaction data from an API. One of the fields in the response is buyer, which may sometimes be null. As a result, I am excluding any entries with a null buyer. This leads to varying numbers of results being displayed. My goal is t ...

What is causing the continuous appearance of null in the console log?

As part of my JavaScript code, I am creating an input element that will be inserted into a div with the id "scripts" in the HTML. Initially, I add a value to this input field using JavaScript, and later I try to retrieve this value in another JavaScript fu ...

Conflicting parameters in the restify.js routing endpoint causing a conflict

Here is the structure of my code: server.get('/currency/:code', currency.find); server.get('/currency/rates', currency.rate_getall); When attempting to access the [/rates] endpoint, the server consistently interprets it as a paramete ...

Is there a more efficient method to achieve this task using JavaScript or jQuery?

Here is the code snippet I am currently using: $(document).ready(function() { //Document Ready $(".examples .example1").click(function() { $(".examples .example1 div").fadeToggle("slow"); $(".examples .example1").toggleClass('focused') ...

Transform an array of objects into an object of objects while maintaining the interior structure

I am searching for a specific solution that I have not come across yet. If such a solution exists, I would greatly appreciate a link to it. Currently, my code looks like this: const obj = {"key": [ { "name": { "companyName": "Something" } }, { "otherT ...

What is the best way to attach a CSS class using an onclick function?

I need to dynamically apply a CSS class to a specific div when clicked using JavaScript. Here is the HTML structure: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv=&qu ...

Switch up a font style using JavaScript to apply a Google font effect

I am attempting to implement a discreet hidden button on a website that triggers a unique Google font effect for all of the h1 elements displayed on the page. However, I am uncertain about the process and unsure if it is achievable. Below is the code snipp ...

The 'slide.bs.carousel' event in Bootstrap carousel is triggered just once

Take a look at my JavaScript code: $('#carousel-container').bind("slide.bs.carousel", function () { //reset the slideImg $('.slideImg',this).css('min-height', ''); //set the height of the slider var ...