Posts

How To Check MongoDB ID Valid Or Not

Image
As you must aware about the object ID in mongo database or MongoDB is 24 characters long so for check is it valid id or not there is no direct validation method in validations package such as node-input-validator. MongoDB - Education Funda So for checking entered id is valid or not we can us below tech-tics: Approach 1 - Simple JS Validation var checkForHexRegExp = new RegExp("^[0-9a-fA-F]{24}$") checkForHexRegExp.test("i am a string") // false checkForHexRegExp.test("5e63c3a5e4232e4cd0074ac2") // true Approach 2 - With Mongo DB Method (Best Way) var ObjectID = require("mongodb").ObjectID ObjectID.isValid("i am a string") // false ObjectID.isValid("5e63c3a5e4232e4cd0274332") // true With Node Input Validator You Can Use Below Method: const id_exists = "required|string|minLength:24|maxLength:24|idExists"   const validator = require ( "node-input-validator" ) const mongoose = require ( 'mongoose...

OG Tags For Social Media Sharing

Image
Share On Social Media OG Tags For Proper Title, Description and Image Social Sharing Step 1: Title Maximum of 65 characters <title>your keyword rich title of the website and/or webpage</title> Step 2: Description Maximum of 155 characters <meta name="description" content="description of your website/webpage, make sure you use keywords!"> Step 3: og:title Maximum 35 characters <meta property="og:title" content="short title of your website/webpage" /> Step 4: og:url Full link to your webpage address <meta property="og:url" content="https://www.example.com/webpage/" /> Step 5: og:description Maximum 65 characters <meta property="og:description" content="description of your website/webpage"> Step 6: og:image Image(JPG or PNG) of size less than 300KB and minimum dimension of 300 x 200 pixel is advised <meta property="og:image" content="//cdn.example.com/uplo...

Check Image URL Exists Or Not WIth PHP

Image
How To Image Or Any File Exists Or Not With PHP Language For checking the URL is exists or not we can use curl request in PHP and we can use same approach in other programming languages also such as JavaScript. So for PHP URL check code is below: function is_url_exist($url){     $ch = curl_init($url);         curl_setopt($ch, CURLOPT_NOBODY, true);     curl_exec($ch);     $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);     $status = ($code == 200) ? true : false; // single liner if else     curl_close($ch);     return $status; } Thanks for reading this blog, I hope it will be helpful for you and please share your feedback in comments section.

Get YouTube Video Thumbnail And Use It With Your Code

Image
Download Any YouTube Video Thumbnail YouTube stores many different types of thumbnails on its server for different devices. You can access it by using the video id which every YouTube video has. You can display the images on your website using a variable $link which holds the id of the video and substituting it in the place for video_ID in the link. Download-Any-Youtube-Video-Thumbnail   Low quality thumbnail: https://img.youtube.com/vi/<YouTube_Video_ID_HERE>/sddefault.jpg Medium quality thumbnail: https://img.youtube.com/vi/<YouTube_Video_ID_HERE>/mqdefault.jpg High quality thumbnail: https://img.youtube.com/vi/<YouTube_Video_ID_HERE>/hqdefault.jpg Maximum quality thumbnail: https://img.youtube.com/vi/<YouTube_Video_ID_HERE>/mqdefault.jpg Such as in this blog we will get thumbnail of this YouTube video: Example: If you want to access the thumbnail of this above video: So the Video ID for this video is: aCB2WRqxxvo So, this is how video thumbnail link loo...

How To Save CK Editor Data Into Database

Image
The "CK Editor" is an HTML editor in which for saving the data into db we can use below function before saving it into DB in PHP language.   function dataready($data) {           $data = trim($data);           $data = stripslashes($data);           $data = htmlspecialchars($data);           return $data; } Before saving data we can call this function now: dataready($_POST['input_name']);  For for showing data into view pages we can use: html_entity_decode($var_article_text); Thanks for reading this blog I hope it will helpful for you.

Standard Way To Create Node JS Fresh Project

Image
As you know in programming world JavaScript is becoming quite famous programming language so in this blog we will discuss how we can create fresh project of NodeJS in standard way. NodeJS - Education Funda Requirements Any server should be installed either Apache or Nginx. NodeJS and NPM should be installed in the operating system.  Steps to Install Fresh Node JS Project: First open your terminal and go to your project directory then run following commands ~ npm init (after hitting this command it will ask some basic questions you can answer it as per your need.   ~ npm init ~ npm install express (it will install express server for your project) ~ npm install mongodb (optional - if you want to use mongo) ~ npm install mongoose (optional - if you want to use mongo) ~ npm install nodemon --save-dev (nodemon package is using for automatically refresh after any change and we're using save dev here because we want to install it for development purpose only) To do setup of licens...

Database Seeding in NodeJS with MongoDB

Image
Seeders in NodeJS Database seeding is a process in which we can put predefined data or dummy data in database as per need. such as the data of countries, cities, etc. is fixed data for everyone for these kind of data we can create database seeding files and we can put all the data into database with the help of 1 command only. Step 1 : We should have model firstly for which we want to create seeding so here is an example model Product. productModel.js Step 2 : As we want to run 'database seeders' separately in one command so have can create one file for seeders and in this file we also need to add database connection so that we can communicate with database because here app.js/index.js database connection doesn't work as we want to run this separately so example seeder.js file is: Seeders.js   Step 3 : Now we can run command node seeders.js to create seeding in database Thanks for reading this article I hope it will help you for creating seeders in node js with mongo datab...