Click continue
Press “I Acknowledge”
Multiselect vercel projects
Click “ “Connect and Return to Vercel”
Takes a long time to complete approx. 5 minutes
Click continue
Press “I Acknowledge”
Multiselect vercel projects
Click “ “Connect and Return to Vercel”
Takes a long time to complete approx. 5 minutes
1. Create an ubuntu container:
docker run -d -p 10000:3000 -p 11000:4000 --name ub-react -v "C:\RajeshWorks\DockerVolumes\React\ReactCompleteApp:/rajesh" ubuntu:latest tail -F /dev/null
2. Execute the docker container:
docker exec -it ub-react bash
3. Update apt-get:
apt-get update
4. Install sudo:
apt-get install sudo -y
5. Install curl:
sudo apt-get install curl -y
6. Add PPA for latest node:
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
NOTE: This command may take some time but do not press ctrl+c.
NOTE: TO find the latest version, go to https://github.com/nodesource/distributions
On this page, find the "Installation instructions" section and find the "Using Ubuntu" under it.
This section will give you the latest version of above curl command.
7. Install latest node:
apt-get install -y nodejs
8. Update and upgrade apt-get:
sudo apt-get update
sudo apt-get upgrade -y
9. Install npm:
sudo apt-get install -y npm
10. Update npm:
npm cache clean -f
sudo npm install -g npm
11. Check the versions of npm and node:
node --version (v20.18.1)
npm --version (11.0.0)
12: Install vim:
apt-get install vim
13. cd rajesh (so that you can see and edit files)
import { useState } from "react";
const StudentList = () => {
const [studentList, setStudentList] = useState([
{ id: 1, firstName: "first001", lastName: "Last001" },
{ id: 2, firstName: "first002", lastName: "last002" },
{ id: 3, firstName: "first003", lastName: "last003" },
{ id: 4, firstName: "first004", lastName: "last004" },
{ id: 5, firstName: "first005", lastName: "last005" },
]);
const [showModal, setShowModal] = useState(false);
const [currentStudent, setCurrentStudent] = useState(null);
const handleAdd = () => {
const newStudent = { id: studentList.length + 1, firstName: "first006", lastName: "last006" };
setStudentList((prevList) => [...prevList, newStudent]);
};
const onBeginEdit = (student) => {
setCurrentStudent(student);
setShowModal(true);
};
const onCompleteEdit = (updatedStudent) => {
setStudentList((prevList) =>
prevList.map((student) =>
student.id === updatedStudent.id ? updatedStudent : student
)
);
setShowModal(false);
};
const onControlChange = (e) => {
const { name, value } = e.target;
setCurrentStudent((prevStudent) => ({
...prevStudent,
[name]: value,
}));
};
return (
<>
<button onClick={handleAdd}>Add New</button>
<table border="1px solid black">
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{studentList.map((student) => (
<tr key={student.id}>
<td>{student.firstName}</td>
<td>{student.lastName}</td>
<td>
<button onClick={() => onBeginEdit(student)}>Edit</button>
</td>
</tr>
))}
</tbody>
</table>
{showModal && currentStudent && (
<div>
<form
onSubmit={(e) => {
e.preventDefault();
onCompleteEdit(currentStudent);
}}
>
<label>First Name</label>
<input
type="text"
name="firstName"
value={currentStudent.firstName}
onChange={onControlChange}
/>
<label>Last Name</label>
<input
type="text"
name="lastName"
value={currentStudent.lastName}
onChange={onControlChange}
/>
<button type="submit">Save</button>
</form>
</div>
)}
</>
);
};
export default StudentList;
import { useState, useEffect } from "react";
const StudentList = () =>
{
const [studentList, setStudentList] = useState([
{
firstName : "",
lastName : ""
}
]);
useEffect(()=> {
setStudentList([{firstName: "first001" , lastName : "Last001"}]);
setStudentList((prevList) => [...prevList , {firstName: "first002", lastName : "last002"}]);
setStudentList((prevList) => [...prevList , {firstName: "first003", lastName : "last003"}]);
setStudentList((prevList) => [...prevList , {firstName: "first004", lastName : "last004"}]);
setStudentList((prevList) => [...prevList , {firstName: "first005", lastName : "last005"}]);
}, []);
const handleAdd = () => {
setStudentList((prevList) => [...prevList , {firstName: "first006", lastName : "last006"}]);
}
return(
<>
<button onClick={handleAdd}>Add New </button>
<ul>
{
studentList.map(student=> {
return (<li>{student.firstName} {student.lastName} </li>); }
)
}
</ul>
</>
);
}
export default StudentList;
Nodejs can support multithreading through use of promises
_ is the numeric separator for javascript, that means the numbers 10_000, 11.23_003 etc ar valid numbers in javascript. They will be treated as and displayed as 1000 , 11,23005 etc by javascript.
You can use & at the end of node command to run the process in background. (may be unix feature)
node xxxx &
ps -> list all processes
kill NNN kills process with id NNN
When you are creating express backend, you have two options: to use CommonJS or to use ECMAScript.
CommonJS is default for Node.
You can specify which one to use in package.json.
When you want to use CommonJS, you specify "type" : "commonjs". This is added in package.json by default when a new node project is created by using "npm init" command.
When you want to use ECMAScript, you have to change this type to module: "type" : "module".
The main difference between ECMAScript and CommonJS is in importing modules: ECMAScript uses "import" statement, while CommonJS uses "require" statement.
The below project create two different Hello, World projects in Express, one with CommonJS and other with ECMAScript.
======================================================================================
STEP 001 : Creating a new express project with commonjs with API code in separate file
======================================================================================
1. Create a React-Node Ubuntu container, with mounted volume.
2. Create a folder commonjs and change directory to that folder:
cd commonjs
3. Run the below command to create a new node project:
npm init
Keep on pressing <Enter> keys on all questions, we are going to use default names and settings only.
Next, install express:
npm install express
4. Inspect package.json by using command "cat package.json". You will find the below line by default:
"type" : "commonjs"
Thus, this project will use commonjs ("require" syntax).
5. Create a index.js file: (because the package.json by default contains the entry "main" : "index.js")
touch index.js
Open this file for editing:
vi index.js
Add the following code to this file:
-----------------------------------------------------------------------
index.js
-----------------------------------------------------------------------
const express = require("express");
const hello001 = require("./hello001.js");
const hello002 = require("./hello002.js");
const app = express();
//both index.js and hello001.js, hello002.js should be in same directory
app.use('/hello001', hello001);
app.use('/hello002', hello002);
app.listen(4000);
-----------------------------------------------------------------------
6. Create an hello001.js file in the same folder with below code:
-----------------------------------------------------------------------
hello001.js
-----------------------------------------------------------------------
const express = require("express");
const router = express.Router();
router.get('/', function(req, res){
res.send('GET route on HELLO 001');
});
router.post('/', function(req, res){
res.send('POST route on HELLO 001.');
});
//export this router to use in our index.js
module.exports = router; //this is required for commonjs
//export default router; //this is required for ECMAScript
-----------------------------------------------------------------------
7. Create an hello002.js file in the same folder with below code:
-----------------------------------------------------------------------
hello002.js
-----------------------------------------------------------------------
const express = require("express");
const router = express.Router();
router.get('/', function(req, res){
res.send('GET route on HELLO 002');
});
router.post('/', function(req, res){
res.send('POST route on HELLO 002.');
});
//export this router to use in our index.js
module.exports = router; //this is required for commonjs
//export default router; //this is required for ECMAScript
-----------------------------------------------------------------------
8. Run the project.
node index.js
The project will start running, but there will be no message displayed since we have not given one.
9. You can check the GET methods on the host computer's browser, browse to (THIS ASSUMES CONTAINER's 4000 port is mapped to 11000 port of host computer)
http://localhost:11000/hello001
and
http://localhost:11000/hello002
You should see the messages: "GET route on HELLO 001" and "GET route on HELLO 002" respectively on the browser.
10. You can check the POST method calls using POSTMAN.
In POSTMAN, use the same URLs as above and simply change API type to POST and send the request. (WE are not using any auth and also there are no request parameters/body required).
You should see the messages: "POST route on HELLO 001" and "POST route on HELLO 002" respectively on the browser.
11. Please find below the package.json for ready reference:
-----------------------------------------------------------------------
package.json
-----------------------------------------------------------------------
{
"name": "commonjs",
"version": "1.0.0",
"description": "",
"license": "ISC",
"author": "",
"type": "commonjs",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"express": "^4.21.2"
}
}
-----------------------------------------------------------------------
======================================================================================
========================================================================================
STEP 002 : Creating a new express project with ECMASCript with API code in separate file
========================================================================================
1. Create a React-Node Ubuntu container, with mounted volume.
2. Create a folder ecmascript and change directory to that folder:
cd ecmascript
3. Run the below command to create a new node project:
npm init
Keep on pressing <Enter> keys on all questions, we are going to use default names and settings only.
==> THE LAST QUESTION ASKED IS "type", for which the default answer is "(commonjs)".
You can type "module" here (without double quotes!, it will add double quotes by itself).
If you missed this, DO NOT WORRY, YOU CAN CHANGE IT IN STEP 4 below.
Next, install express:
npm install express
4. Inspect package.json by using command "cat package.json".
If you have already specified "type" as "module" in step 3 above, then you are good to go.
If you missed it in step 3 above, you can now edit package.json and change the type to module.
Open package.json in vi editior, if you find the below line:
"type" : "commonjs"
change it to:
"type" : "module" [DIFFERENCE 001]
5. Create a index.js file: (because the package.json by default contains the entry "main" : "index.js")
touch index.js
Open this file for editing:
vi index.js
Add the following code to this file:
-----------------------------------------------------------------------
index.js
-----------------------------------------------------------------------
import express from "express"; //[DIFFERENCE 002]
import hello001 from "./hello001.js"; //[DIFFERENCE 003]
import hello002 from "./hello002.js"; //[DIFFERENCE 004]
const app = express();
//both index.js and hello001.js, hello002.js should be in same directory
app.use('/hello001', hello001);
app.use('/hello002', hello002);
app.listen(4000);
-----------------------------------------------------------------------
6. Create an hello001.js file in the same folder with below code:
-----------------------------------------------------------------------
hello001.js
-----------------------------------------------------------------------
import express from "express"; //[DIFFERENCE 005]
const router = express.Router();
router.get('/', function(req, res){
res.send('GET route on HELLO 001');
});
router.post('/', function(req, res){
res.send('POST route on HELLO 001.');
});
//export this router to use in our index.js
//module.exports = router; //this is required for commonjs
export default router; //this is required for ECMAScript //[DIFFERENCE 006]
-----------------------------------------------------------------------
7. Create an hello002.js file in the same folder with below code:
-----------------------------------------------------------------------
hello002.js
-----------------------------------------------------------------------
import express from "express"; //[DIFFERENCE 007]
const router = express.Router();
router.get('/', function(req, res){
res.send('GET route on HELLO 002');
});
router.post('/', function(req, res){
res.send('POST route on HELLO 002.');
});
//export this router to use in our index.js
//module.exports = router; //this is required for commonjs
export default router; //this is required for ECMAScript //[DIFFERENCE 008]
-----------------------------------------------------------------------
8. Run the project.
node index.js
The project will start running, but there will be no message displayed since we have not given one.
9. You can check the GET methods on the host computer's browser, browse to (THIS ASSUMES CONTAINER's 4000 port is mapped to 11000 port of host computer)
http://localhost:11000/hello001
and
http://localhost:11000/hello002
You should see the messages: "GET route on HELLO 001" and "GET route on HELLO 002" respectively on the browser.
10. You can check the POST method calls using POSTMAN.
In POSTMAN, use the same URLs as above and simply change API type to POST and send the request. (WE are not using any auth and also there are no request parameters/body required).
You should see the messages: "POST route on HELLO 001" and "POST route on HELLO 002" respectively on the browser.
11. Below is the package.json for ready reference:
-----------------------------------------------------------------------
package.json
-----------------------------------------------------------------------
{
"name": "ecmascript",
"version": "1.0.0",
"description": "",
"license": "ISC",
"author": "",
"type": "module",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"express": "^4.21.2"
}
}
-----------------------------------------------------------------------
The only change you will notice will be in the "type" line.
========================================================================================
LangGraph Orchestration vs CrewAI Orchestration The following table compares LangGraph and CrewAI orchestration across their menta...