Skip to main content

Posts

Why is this async/Promise method running synchronously?

I'm really a noob in JavaScript and I'm trying to write a small ElectronJS/NodeJS app. I think the purpose of the App is not relevant to the question, suffice it to say that the App will listen to TCP connections that will send ~100MB of XML content and then will do some further processing on the parsed XML. Since the XML content is "large" the parsing is taking some time to process, so I decided to put the parsing in an asynchronous function but the code is apparently running synchronously. I'm not sure if I'm doing something wrong or if it's just because of the single-thread (AFAIU) nature of JavaScript. var net = require('net'); const fs = require('fs'); const { XMLParser, XMLBuilder, XMLValidator} = require("fast-xml-parser"); const parser = new XMLParser(); var file_counter = 0; var server = net.createServer(function(connection) { console.log('Client Connected'); var content = ""; connection.o

Why am I not seeing a TypeScript error here?

I would expect the following code (inside an arbitrary Class) to show a TypeScript error in VSCode. But it doesn't. Why? protected someMethod (someArg?: boolean) { this.doSomething(someArg) } protected doSomething (mustBePassedBoolean: boolean) { /* ... */ } The tooltip doesn't even acknowledge that someArg should be boolean|undefined : I'm guessing this must be an eslint configuration error because the same thing in TypeScript playground acts as I would expect. But I'm not seeing any eslint configuration errors in the VSCode console. Any advice on troubleshooting VS Code eslint problems like this? Edit It's worth noting that I am seeing some expected TypeScript errors, in the same file. As far as I can tell this seems to only happen with vars I would expect to be cast as |undefined . Via Active questions tagged javascript - Stack Overflow https://ift.tt/yBvh1Lu

V-model binding always reset text input Vue

So I have an Text Input that filled based on string that stored in cookies. Something like a Remember me. when I do the value binding the cookies using :value I can't type the new value although there is no cookie being stored. here is the code <template> <GuestLayout class="bg-neutral"> <Head title="Log in" /> <div v-if="status" class="mb-4 font-medium text-sm text-white-600"> </div> <form @submit.prevent="submit"> <div> <InputLabel for="email" value="Email" /> <TextInput id="email" type="email" class="mt-1 block w-full text-neutral-focus focus:border-accent" v-model="form.email" :value="rememberedEmail"

ChartJS Chart how to config Scales

I am creating a website about Bitcoins and using some interactive Charts from ChartJS. Until now the scales in the Charts are changing with the data. But I think to compare the differencesbetween the years I would like them to not change and stay the same. So the scale sould be always from 0 - 110. I already tried to do this but it does't work: The trick with the max and min... scales:{ r: { ticks: { beginAtZero: true, min: 150, max: 150, stepSize: 10, If somebody could help me I would be really greatfull! Fiddle in the comment. Cheers! Via Active questions tagged javascript - Stack Overflow https://ift.tt/Z02RAK7

How to close popup box when clicked outside or when page is scrolled? [duplicate]

I am creating a page with image map that has a popup box. It works ok but I am not sure how to close the popup box when user clicks outside of the box or when the users scrolls the page. Currently the popup box remains on the page until the user closes the box by selecting 'X' button. Here is link to my jsfiddle - https://jsfiddle.net/dyxc2qe5/2/ Thanks. $(function() { $('.map').maphilight(); }); var myData = { "left-eye": { "top" : -20, "left" : -200, "title": "", "image":"", "description": "Lorem ipsum A dolor sin amet. ." }, "mouth": { "top" : 20, "left" : 200, "title": "", "description": "Lorem ipsum B dolor sin amet. Lorem ipsum B dolor sin amet.Lorem ipsum B dolor sin amet.Lorem ipsum B dolor sin amet.Lorem ipsum B do

on hover card should scale out of swiper

I'm trying to build a swiper just like a Netflix, and trying to achieve the same hover effect. But when I'm hovering over the card, its not scaling out of swiper and stays inside the swiper container. Below is my code. <!DOCTYPE html> <html > <head> <meta charset="utf-8" /> <title>Swiper demo</title> <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1" /> <!-- Link Swiper's CSS --> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/swiper@10/swiper-bundle.min.css" /> <!-- Demo styles --> <style> html, body { position: relative; height: 100%; } body { background: #1e1e27; font-family: Helvetica Neue, Helvetica, Arial, sans-serif; font-size: 14px; color: #000; mar

how fix error: MongoNotConnectedError: Client must be connected before running operations

HY all , I have a problem when I running this code:- the file productinit.js const product = require('../model/product'); const mongoose= require('mongoose'); const connectDB = async () => { await mongoose.connect('mongodb://127.0.0.1:27017/orders', {bufferTimeout: null}); console.log('Connected to MongoDB'); }; connectDB(); const products = [ new product({ imagePath:"/images/about/a1.png", productName: "iphone 8+ ", price: 200, information: { displaySize: 6.5, storageCapacity: 64, CameraResolution: 16, numberOfSIM: "Dual SIM" }}), new product({ imagePath:"/images/about/a2.png", productName: "iphone 8 ", price: 240, information: { displaySize: 5.5, storageCapacity: 64, CameraResolution: 16, numberOfSIM: "D