Posts

Javascript detect connection speed

Image
JavaScript detect connection speed Ever feel like your internet is running slow? Webpages seem sluggish while uploads and downloads take forever! It's very frustrating, especially when you pay for high-speed internet. As a developer, we need to find the current speed and load the pages accordingly. So if you want to get the connection speed in JS you can use the  Navigator.connection  object. Let's take an example: navigator.connection.addEventListener( 'change' , () => { let currRtt = navigator.connection.rtt; let effType = navigator.connection.effectiveType; console.log( 'current connections' , currRtt, effType) }) so the above example will trigger an event whenever there will be some changes in the network. So let's test it by changing the network connections. As you can see in logs whenever I changed the network type from network tab events gets fired and it printed the current connections types. Javascript detect...

Remove property from Javascript Object

Image
How to remove property from a JavaScript object If you want to remove property from a JavaScript object then you can do by following ways. Remove JavaScript Object Property lets create one object so we can run and test it. var user = { "id": "1001", "name": "Vikas", "email": "test@test.com", "password": "TesTP2ss", "createdAt": "20-08-2019" }; The  will be as follows: Now we can remove the object property from the following ways: Using delete operator: as we have seen the user's object now before sending to frontend we will delete the password property and then we will send it. delete user.password; >>true Or alternatively, you can do the following way as well. delete user['password']; >>true If delete won't work then you can use the following: user . password = undefined ; Please le...

Ionic ios build fails, error archive not found : Error code 65 for command: xcodebuild with args

If you are working on ionic app, and you are trying to create iOS build then usually we use the following command: ionic cordova build ios OR ionic cordova build ios --device --prod --release while creating build if you get following error: ✖ cordova build ios - failed! [ ERROR ] An error occurred while running cordova build ios (exit code 1):          error: archive not found at path '/Users/work/MyApp/platforms/ios/MyAppp.xcarchive'         ** EXPORT FAILED **         CordovaError: Promise rejected with non-error: 'Error code 65 for command: xcodebuild with args:   Then You have to use the following command: ionic cordova build ios -- --buildFlag="-UseModernBuildSystem=0" if this won't work then you can update and or create a build.json file. { "ios" : { "release" : { ..., "buildFlag" : [ ...

Mastering in Javascript | How do JavaScript closures work?

Image
How do JavaScript closures work? When I started learning some advanced concepts of JavaScript that time I got to know about closures but when tried to understand it but it was like leave me alone. Then I did some research on it but still, I was getting only theoretical concepts of closures. So I thought might be I am not alone who don't understand closures so I tried to explain it with examples. What is Closure in JavaScript? A closure is a function having access to the parent scope, even after the parent function has closed.    A closure is one way of supporting first-class functions; it is an expression that can reference variables within its scope (when it was first declared), be assigned to a variable, be passed as an argument to a function, or be returned as a function result. this is the terminology used to explain the closure but I know how hard it is to understand, so let's go by examples. Example of Closures in JavaScript function ...

MongoDB remove unique constraint

Image
MongoDB Remove the unique constraint: Src: https://en.wikipedia.org/wiki/MongoDB Today, I'm working on a RESTful API Using Node.js With Express and Mongoose example, and I ran into a problem with the MongoDB Schema: POST : { username: 'vikaskad' , email: 'testmail@test.com' , name : 'Vikas Kad' } { [ MongoError : E11000 duplicate key error index : ecomm_database . users . $email_1 dup key : { : "testmail@test.com" }] name : 'MongoError' , err : 'E11000 duplicate key error index: ecomm_database.users.$email_1 dup key: { : "testmail@test.com " }' , and my schema is as follows: var Product = new Schema ({ username : { type : String , required : true }, email : { type : String ,unique:true, required : true }, name : { type : String }, createdAt : { type : Date , default : Date . now } }); but after some database inser...