0% found this document useful (0 votes)
5 views8 pages

Node.js CRUD Operations and Setup Guide

This document contains notes on using Node.js and Express.js, including commands for managing Node processes, installing packages, and setting up CRUD operations with a MongoDB database using Mongoose. It also covers the use of EJS for rendering dynamic web pages and includes examples of creating, reading, updating, and deleting user data. Additionally, it mentions the integration of Cloudinary for image storage and the setup for handling cookies with JWT and bcrypt.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views8 pages

Node.js CRUD Operations and Setup Guide

This document contains notes on using Node.js and Express.js, including commands for managing Node processes, installing packages, and setting up CRUD operations with a MongoDB database using Mongoose. It also covers the use of EJS for rendering dynamic web pages and includes examples of creating, reading, updating, and deleting user data. Additionally, it mentions the integration of Cloudinary for image storage and the setup for handling cookies with JWT and bcrypt.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

NODE JS NOTES

tasklist /FI "IMAGENAME eq [Link]"


taskkill /F /IM [Link]
netstat -ano | findstr :3000
taskkill /F /PID <PID>
taskkill /IM [Link] /F

To install global package : npm i -g nodemon(Packagename)

To unistall
: npm uninstall packagename

Exporting one moduleto another

1st [Link]

2nd const name=require(“ ./path“)

Npm i chalk (it will helps us to style color to our text )


npm run chacha
// monoosh creating data
[Link]("/create",async function(req,res){
let creteduser=await [Link]({
name:"kaushal",
email:"kaushal@[Link]",
username:"kaushal"
})
[Link](creteduser)
})

[Link]("/update",async function(req,res)
{
//[Link](findone,update,{new:true})
let updateduser=await [Link]({username:"kaushal"},{name:"ram"},{new:true})
[Link](updateduser)
})

Cloudinary website this webiste helps us to store images

EXPRESS JS
(Framework)

Ek npm package hai

const express=require('express')
const app=express();

//this is known as parser


[Link]([Link]()); // json based data ko redable karti hai
[Link]([Link]({extended:true}))

[Link]('/',function(req,res)
{
[Link]("hey sanamika,this side kaushal")
})
[Link](3000)

Project 1

Npm init -y
Install express; npm I express

Setting up ejs for egs pages


Intall ejs from npm
Setup ejs for middleware

<%=2+2%> in ejs file it isused for calculation


Ine ejs we can perform some dynamic stuff

Setting up public static files

Const path=express(‘path’)
[Link]([Link]([Link](__dirname,'public')))

This is done necause in ejs file when we link out style then we don’t have to methion trhe
public path of the fileeg /public/cstylesheets/[Link] so not using this we can directly use
stylesheets/[Link]

To make a dynamic parth

[Link](“/kaushal/:username” function(req,res){

[Link](`welcome ${[Link]}`)

}) // here at username anything wwe will write we will be redirected to what the function says
CRUD USING NODEJS

const express=require('express')
const app=express();
const userModel=require("./ussermodel")

[Link]("/",function(req,res)
{
[Link]("hey sanamika")
})

[Link]("/create",async function(req,res){
let creteduser=await [Link]({
name:"kundan",
email:"kundan@[Link]",
username:"kundan"
})
[Link](creteduser)
})

[Link]("/update",async function(req,res)
{
//[Link](findone,update,{new:true})
let updateduser=await [Link]({username:"kaushal"},{name:"ram"},{new:true})
[Link](updateduser)
})

[Link]("/read",async function(req,res)
{
let readuser=await [Link]() //{username:"kaushal"}under find
[Link](readuser)
})

[Link]("/delete",async function(req,res)
{
let deleteuser=await [Link]({name:"kaushal"})
[Link](deleteuser)
})

[Link](3000);

HOW TO WRITE MONGOOSE SETUP


Npm i mongoose
const mongoose=require('mongoose')

[Link]("mongodb://[Link]:27017/testapp1");
const userSchema=new [Link]({
image:String,
email:String,
name:String,
}
)

[Link]=[Link]('User',userSchema)
Crud operation setup

const express=require('express')
const app=express();

const userModel=require('./models/User')

const path=require('path')
[Link]([Link]())
[Link]([Link]({extended:true}))

[Link]([Link]([Link](__dirname,'public')))
[Link]("view engine","ejs");
[Link]("/",function(req,res)
{
// [Link]("hey sanamika ");
[Link]('index')
})

[Link]("/delete/:id",async function(req,res)
{
let alluser=await [Link]({_id:[Link]})
[Link]("/read")
})

[Link]("/read",async function(req,res)
{
let alluser=await [Link]()
[Link]("read",{alluser})
})

[Link]("/create",async function(req,res)
{
const {name,email,image}=[Link]

let createduser=await [Link]({


name:name,
email:email,
image:image
})
[Link]("read")
// [Link](createduser)
})
[Link](3000)

Cookie wala part

npm i jsonwebtoken bcrypt


const backendUrl=[Link].VITE_BACKEND_URL

Backend

{
"version": 2,
"builds": [
{
"src": "[Link]",
"use": "@vercel/node",
"config": {
"includeFiles": [
"dist/**"
]
}
}
],
"routes": [
{
"src": "/(.*)",
"dest": "[Link]"
}
]
}
FrontEnd

{
"rewrites": [
{
"source": "/(.*)",
"destination": "/"
}
]
}

You might also like