Posts

Showing posts from December, 2020

Rspec Tutorial - vigoroom

 Ch 00: Introduction Step 01: mkdir rspec_tutorial Step 02: cd rspec_tutorial Step 03: mkdir spec We are going to store our RSpec files in this folder. RSpec files are known as “specs”. If this seems confusing to you, you can think of a spec file as a test file. RSpec uses the term “spec” which is a short form for “specification”. Step 04: Let’s return to our Hello World code. Let’s return to our Hello World code. Open a text editor and add the following code − class HelloWorld def say_hello "Hello World!" end end describe HelloWorld do context “ When testing the HelloWorld class ” do it "should say 'Hello World' when we call the say_hello method" do hw = HelloWorld . new message = hw . say_hello expect ( message ). to eq "Hello World!" end end end Step 05: save this to a file named hello_world_spec.rb in the spec folder that you created above...

Rspec Project run first - vigoroom

Rspec project taken by rinku for do some work for that he gives credentials by dharmendra after that i install it run bundle create the database shikha blog prefer for that https://shikhapandey98.blogspot.com/2019/10/install-mysql-on-ubuntu-18.html mysql ki kuch error aa rahi thi toh mysql ka password nai pata tha  rinku sir ne mysql ka password change karwaya shikha ke blog ke through usmein last second wala command nai chalaya bundle install nai ho raha tha gem install bundler karaya toh chal gaya yeh fir ] Install Mysql On Ubuntu 18.04 1. sudo apt-get install mysql-server mysql-client libmysqlclient-dev 2. sudo service mysql status 3.  mysql -u root -p   yeh nai chalega shayad 4. sudo mysql -u root -p 5. uninstall plugin validate_password; 6. ALTER USER 'root'@'localhost' IDENTIFIED BY 'root'; 7.  ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root'; 8. SELECT user,authentication_string,plugin,host FROM mysql....

home.js

import React ,{ useState , useEffect , useContext } from 'react' import { UserContext } from '../../App' const Home = () => { const [ data , setData ] = useState ([]) const { state , dispatch } = useContext ( UserContext ) useEffect (() => { fetch ( '/allpost' ,{ headers : { "Authorization" : "Bearer" + localStorage . getItem ( "jwt" ) } }). then ( res => res . json ()) . then ( result => { console . log ( result ) setData ( result . posts ) }) },[]) const likePost = ( id ) => { fetch ( '/like' ,{ method : "put" , headers : { "Content-Type" : "application/json" , "Authorization" : "Bearer" + localStorage . getItem ( "jwt" ) }, body : JSON . stringify ({ PostId : id }) }). then ( res ...

create.js

  import React ,{ useState , useEffect , useContext } from 'react' import { UserContext } from '../../App' const Home = () => { const [ data , setData ] = useState ([]) const { state , dispatch } = useContext ( UserContext ) useEffect (() => { fetch ( '/allpost' ,{ headers : { "Authorization" : "Bearer" + localStorage . getItem ( "jwt" ) } }). then ( res => res . json ()) . then ( result => { console . log ( result ) setData ( result . posts ) }) },[]) const likePost = ( id ) => { fetch ( '/like' ,{ method : "put" , headers : { "Content-Type" : "application/json" , "Authorization" : "Bearer" + localStorage . getItem ( "jwt" ) }, body : JSON . stringify ({ PostId : id }) }). then ( re...

home.js recent

  import React ,{ useState , useEffect , useContext } from 'react' import { UserContext } from '../../App' const Home = () => { const [ data , setData ] = useState ([]) const { state , dispatch } = useContext ( UserContext ) useEffect (() => { fetch ( '/allpost' ,{ headers : { "Authorization" : "Bearer" + localStorage . getItem ( "jwt" ) } }). then ( res => res . json ()) . then ( result => { console . log ( result ) setData ( result . posts ) }) },[]) const likePost = ( id ) => { fetch ( '/like' ,{ method : "put" , headers : { "Content-Type" : "application/json" , "Authorization" : "Bearer" + localStorage . getItem ( "jwt" ) }, body : JSON . stringify ({ PostId : id }) }). then ( re...

post.js old i instagam youtube mern app

const express = require ( 'express' ) const router = express . Router () const mongoose = require ( 'mongoose' ) const requireLogin = require ( '../middleware/requireLogin' ) const Post = mongoose . model ( "Post" ) router . get ( '/allpost' , requireLogin ,( req , res ) => { Post . find () . populate ( "postedBy" , "_id name" ) . then ( posts => { res . json ({ posts }) }) . catch ( err => { console . log ( err ) }) }) router . post ( '/createpost' , requireLogin ,( req , res ) => { const { title , body , pic } = req . body if (! title ||! body ||! pic ){ return res . status ( 422 ). json ({ error : 'please add all the fields' }) } req . user . password = undefined const post = new Post ({ title , body , photo : pic , postedBy : req . user }) post . save (). then ( result => { re...

post.js in instagram clone youtube mern

  const express = require ( 'express' ) const router = express . Router () const mongoose = require ( 'mongoose' ) const requireLogin = require ( '../middleware/requireLogin' ) const Post = mongoose . model ( "Post" ) router . get ( '/allpost' , requireLogin ,( req , res ) => { Post . find () . populate ( "postedBy" , "_id name" ) . then ( posts => { res . json ({ posts }) }) . catch ( err => { console . log ( err ) }) }) router . post ( '/createpost' , requireLogin ,( req , res ) => { const { title , body , pic } = req . body if (! title ||! body ||! pic ){ return res . status ( 422 ). json ({ error : 'please add all the fields' }) } req . user . password = undefined const post = new Post ({ title , body , photo : pic , postedBy : req . user }) post . save (). then ( result => { ...

Getting Data in Request Body in Instagram Clone

  Step 01: Create the folder named routes and create file auth.js in that   Step 02: We need to require express and use it in router  const express = require ( 'express' ) const router = express . Router ()  Step 03:  Create a route and also export that route router . get ( '/' ,( req , res ) => { res . send ( "hello user" ) }) Step 04: Now We can Register this route in App.js: app . use ( require ( './routes/auth' )) Step 05: Make the Signup Route basically with console.log and test it at the Postman router . post ( '/signup' ,( req , res ) => { console.log(req.body.name) }) In Postman- Headers : content-Type:Application/json Body: { name:"mukesh" } but it will not work in response because in postamn  our express server does not pass the request to the json , we need to tell it to the server  app . use ( express . json ()) this is a type of middleware and i will write it in the app.use - because we want to take  al...