Tuesday, February 7, 2023
Learning Code
  • Home
  • JavaScript
  • Java
  • Python
  • Swift
  • C++
  • C#
No Result
View All Result
  • Home
  • JavaScript
  • Java
  • Python
  • Swift
  • C++
  • C#
No Result
View All Result
Learning Code
No Result
View All Result
Home JavaScript

forEach not working as expected in NodeJs – JavaScript – SitePoint Forums

learningcode_x1mckf by learningcode_x1mckf
September 6, 2022
in JavaScript
0
Time limit for notify – JavaScript – SitePoint Forums
74
SHARES
1.2k
VIEWS
Share on FacebookShare on Twitter


You might also like

An Introduction to Lodash and Its Benefits for JavaScript Developers – MUO – MakeUseOf

Mimic Javascript actions on identical element? – JavaScript – SitePoint

How To Hire a Professional JavaScript Developer and Find the Best … – Intelligent Living

I’m importing the excel sheet in DB with the assistance of Nodejs, I’m unable to authenticate and return the error as exist already the userid when the merchandise.USER_ID already exists in DB. my server goes crash and returns an error as Error [ERR_HTTP_HEADERS_SENT]: Can not set headers after they're despatched to the shopper

Please assist in the code how I repair this subject and make it, If the merchandise.USER_ID already exists return error else insert.

var XLSX = require("xlsx");
const fs = require("fs");

attempt {
	const transaction = await con.transaction();
	var workbook = XLSX.readFile("myfile.xlsx");
	let json_data = XLSX.utils.sheet_to_json(workbook.Sheets.Sheet1);

	let rely = 0;
	json_data.map(async (merchandise) => 
		let stmt1 = await con.question("SELECT * FROM `desk` WHERE `user_id` = :userid",  replacements:  userid: merchandise.USER_ID , sort: con.QueryTypes.SELECT );
		if (stmt1.size > 0) 
			await transaction.rollback();
			return res.json( message: "exist already the userid" );
		 else 
			let stmt2 = await con.question("INSERT INTO `desk` (`user_id` , `user_name`) VALUES ( :user_id , :user_name)", 
				replacements: 
					user_id: merchandise.USER_ID,
					user_name: merchandise.USER_NAME,
				,
				sort: con.QueryTypes.INSERT,
				transaction: transaction,
			);
			rely++;
			if (rely == json_data.size) 
				await transaction.commit();
				return res.json( message: "file uploaded efficiently.." );
			
		
	);
} catch (err) 
	await transaction.rollback();
	return res.json( code: 500, message:  msg: "SQL ERROR" , error: err.stack, standing: "error" );

A doable clue is from https://stackoverflow.com/questions/26307920/res-json-cant-set-headers-after-they-are-sent the place they are saying that res.json ends in sending a response to the shopper, so if you’re additionally trying to ship a response from another a part of the code then you’ll be trying to ship two units of responses, leading to that error message.



Source link

Share30Tweet19
learningcode_x1mckf

learningcode_x1mckf

Recommended For You

An Introduction to Lodash and Its Benefits for JavaScript Developers – MUO – MakeUseOf

by learningcode_x1mckf
February 6, 2023
0
Google expands open source bounties, will soon support Javascript fuzzing too – ZDNet

An Introduction to Lodash and Its Benefits for JavaScript Developers  MUO - MakeUseOf Source link

Read more

Mimic Javascript actions on identical element? – JavaScript – SitePoint

by learningcode_x1mckf
February 6, 2023
0
Google expands open source bounties, will soon support Javascript fuzzing too – ZDNet

Mimic Javascript actions on identical element? - JavaScript  SitePoint Source link

Read more

How To Hire a Professional JavaScript Developer and Find the Best … – Intelligent Living

by learningcode_x1mckf
February 6, 2023
0
Google expands open source bounties, will soon support Javascript fuzzing too – ZDNet

How To Hire a Professional JavaScript Developer and Find the Best ...  Clever Residing Source link

Read more

How to Use Regular Expressions in JavaScript – MUO – MakeUseOf

by learningcode_x1mckf
February 6, 2023
0
Google expands open source bounties, will soon support Javascript fuzzing too – ZDNet

How to Use Regular Expressions in JavaScript  MUO - MakeUseOf Source link

Read more

Web Development & JavaScript Trends in 2023 – Electronicsmedia

by learningcode_x1mckf
February 6, 2023
0
Google expands open source bounties, will soon support Javascript fuzzing too – ZDNet

Web Development & JavaScript Trends in 2023  Electronicsmedia Source link

Read more
Next Post
Sorting a Python Dictionary: Values, Keys, and More

Sorting a Python Dictionary: Values, Keys, and More

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Related News

Best Websites To Learn C++ Programming Online: Top 10

Best Websites To Learn C++ Programming Online: Top 10

September 8, 2022
Time limit for notify – JavaScript – SitePoint Forums

forEach not working as expected in NodeJs – JavaScript – SitePoint Forums

September 6, 2022
File System Operations – Real Python

File System Operations – Real Python

January 17, 2023

Browse by Category

  • C#
  • C++
  • Java
  • JavaScript
  • Python
  • Swift

RECENT POSTS

  • JobRunr, the Java Scheduler Library, Released Version 6.0 – InfoQ.com
  • An Introduction to Lodash and Its Benefits for JavaScript Developers – MUO – MakeUseOf
  • "Used properly, Python is not slower than C++" – eFinancialCareers (US)

CATEGORIES

  • C#
  • C++
  • Java
  • JavaScript
  • Python
  • Swift

© 2022 Copyright Learning Code

No Result
View All Result
  • Home
  • JavaScript
  • Java
  • Python
  • Swift
  • C++
  • C#

© 2022 Copyright Learning Code

Are you sure want to unlock this post?
Unlock left : 0
Are you sure want to cancel subscription?