{"id":8335,"date":"2022-06-21T18:51:12","date_gmt":"2022-06-21T13:21:12","guid":{"rendered":"https:\/\/selfimagination.in\/tips\/?p=8335"},"modified":"2022-08-09T17:48:36","modified_gmt":"2022-08-09T12:18:36","slug":"api-using-node-react-express-mysql","status":"publish","type":"post","link":"https:\/\/selfimagination.in\/tips\/api-using-node-react-express-mysql\/","title":{"rendered":"API using Node React Express MySQL Sequelize (For Backend or Server Side)"},"content":{"rendered":"\n<p>This Aritcle for Create API Using Node React Express MySQL Sequelize, Creating a Local Server, Server Side API for MySQL Connection <\/p>\n\n\n\n<p>\u091c\u092c \u092d\u0940 \u0906\u092a\u0915\u094b React \u092e\u0947 Database \u0938\u0947 Connect \u0915\u0930 \u0915\u094b\u0908 \u092d\u0940 Project \u092c\u0928\u093e\u0928\u093e \u0939\u094b \u0924\u092c \u0906\u092a\u0915\u094b \u0938\u092c\u0938\u0947 \u092a\u0939\u0932\u0947 \u090f\u0915 API  \u0915\u0947 \u0932\u093f\u090f \u090f\u0915 \u0905\u0932\u0917 Project \u092c\u0928\u093e\u0928\u093e \u0939\u094b\u0917\u093e \u0964 \u091c\u093f\u0938\u092e\u0947 \u0906\u092a SQL Logic \u0932\u093f\u0916 \u0909\u0928\u0915\u094b url \u0938\u0947 \u0932\u093f\u0902\u0915 \u0915\u0930 \u0926\u0947\u0902\u0917\u0947 \u0924\u093e\u0915\u093f \u091c\u092c \u092d\u0940 \u0906\u092a \u0926\u0942\u0938\u0930\u0947 Project \u0938\u0947 url \u092f\u093e API Call \u0915\u0930\u0947\u0902\u0917\u0947 \u0924\u094b Result Json \u092e\u0947 Display \u0939\u094b\u0928\u0947 \u0932\u0917\u0947\u0917\u093e \u0964 \u091a\u0932\u093f\u090f \u0936\u0941\u0930\u0942 \u0915\u0930\u0924\u0947 \u0939\u0948\u0902 \u0964 <\/p>\n\n\n\n<p>\u0907\u0938 Article \u0915\u094b \u0932\u093f\u0916\u0924\u0947 \u0938\u092e\u092f \u092e\u0947 \u092f\u0939 \u092e\u093e\u0928 \u0930\u0939\u093e \u0939\u0941 \u0915\u0940 \u0906\u092a Database \u0915\u0947 \u092c\u093e\u0930\u0947 \u092e\u0947 \u091c\u093e\u0928\u0915\u093e\u0930\u0940 \u0930\u0916\u0924\u0947 \u0939\u0948\u0902 \u0914\u0930 \u0906\u092a\u0915\u094b javascript \u0915\u0947 \u092c\u093e\u0930\u0947 \u092e\u0947 \u091c\u093e\u0928\u0915\u093e\u0930\u0940 \u0939\u0948\u0902 , \u0907\u0938\u0932\u093f\u090f \u092e\u0948\u0902\u0928\u0947 \u0907\u0938\u092e\u0947 Concept Clear \u0915\u093f\u092f\u093e \u0939\u0948\u0902 \u0915\u0940 \u0915\u093f\u0938 \u0924\u0930\u0939 \u0938\u0947 \u0939\u092e API \u092c\u0928\u093e \u0938\u0915\u0924\u0947 \u0939\u0948\u0902 \u0964 \u092f\u0926\u093f \u0906\u092a Begineers \u0939\u0948\u0902 \u0914\u0930 deep \u092e\u0947 \u0938\u092e\u091d\u0928\u093e \u091a\u093e\u0939\u0924\u0947 \u0939\u0948\u0902 \u0924\u094b \u0906\u092a\u0915\u094b \u0907\u0938 Blog \u092a\u0930 \u0907\u0938\u0938\u0947 \u0938\u0902\u092c\u0902\u0927\u093f\u0924 \u0905\u0928\u094d\u092f Article \u092e\u093f\u0932 \u091c\u093e\u090f\u0902\u0917\u0947 \u0964  <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. Make Project <\/h2>\n\n\n\n<ol class=\"wp-block-list\"><li><strong>Create <strong>MySQL<\/strong><\/strong> <strong>Database <\/strong><ol><li>Create Database (MyDB) <\/li><li>Make Table (studentmst) <\/li><li>Insert Data<\/li><\/ol><\/li><li><strong>Create API Project <\/strong><ol><li>Make a Directory named ApiProject<\/li><li>Open Directory Within Visual Code <\/li><li>Open Terminal <\/li><li>Make Package JSON using (npm inti -y) <\/li><li>Install Dependency using (npm i express mysql2 sequelize cors)<\/li><li>Understand Project Structure <\/li><li>Database Connection using database.js <\/li><li>Connect Table using Student.js <\/li><li>Routing using Index.js    <\/li><li>Run Server <\/li><\/ol><\/li><\/ol>\n\n\n\n<p><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">1. Create MySQL Database <\/h2>\n\n\n\n<p><a href=\"https:\/\/selfimagination.in\/tips\/category\/mysql\/\">MySQL \u0938\u0940\u0916\u0928\u0947 \u0915\u0947 \u0932\u093f\u090f \u0915\u094d\u0932\u093f\u0915 \u0915\u0930\u0947 \u0964 <\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1.1 Create Database <\/h3>\n\n\n\n<p>Wamp \u0914\u0930 Xampp \u0915\u093e \u0909\u092a\u092f\u094b\u0917 \u0915\u0930 \u0906\u092a\u0915\u094b phpmyadmin \u0938\u0947 database \u092c\u0928\u093e\u0928\u093e \u0939\u094b\u0917\u093e \u0964 <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">CREATE DATABASE MyDB;<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1.2 Create Table <\/h3>\n\n\n\n<p>\u0905\u092c \u0906\u092a\u0915\u094b \u0928\u0940\u091a\u0947 \u0926\u093f\u090f syntax \u0938\u0947 Table \u092c\u0928\u093e\u0928\u093e \u0939\u094b\u0917\u0940 <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"sql\" class=\"language-sql\">\n\nCREATE TABLE IF NOT EXISTS `studentmst` (\n  `id` int(9) NOT NULL AUTO_INCREMENT,\n  `stud_nm` varchar(40) NOT NULL,\n  `stud_class` varchar(20) NOT NULL,\n  PRIMARY KEY (`id`)\n) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;\n\n<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1.3 Insert Data into Table <\/h3>\n\n\n\n<p>Testing \u0915\u0947 \u0932\u093f\u090f \u0906\u092a \u0928\u0940\u091a\u0947 \u0926\u093f\u090f \u0917\u090f Syntax \u0938\u0947 \u0909\u092a\u0930\u094b\u0915\u094d\u0924 Table \u092e\u0947 Data Insert \u0915\u0930\u0947\u0902\u0917\u0947 \u0964  <\/p>\n\n\n\n<pre title=\"Insert Data \" class=\"wp-block-code\"><code lang=\"sql\" class=\"language-sql\">INSERT INTO `studentmst` (`id`, `stud_nm`, `stud_class`) VALUES\n(1, 'Sandip Nigam', '12th'),\n(2, 'Rishabh Sharma', '11th'),\n(3, 'Rakesh Mali', '12th'),\n(4, 'Vishal Garg', '12th');<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">2. Create API Project Using Node React Express MySQL Sequelize<\/h2>\n\n\n\n<p>\u0905\u092c \u0906\u092a\u0915\u094b \u090f\u0915 API project \u092c\u0928\u0928\u093e \u0939\u0948\u0902 \u0964 \u091c\u093f\u0938\u092e\u0947 \u0915\u0940 \u0939\u092e\u0928\u0947 \u091c\u094b Database \u092c\u0928\u093e\u092f\u093e \u0939\u0948 \u0909\u0938\u0915\u0947 Data \u0915\u094b Get \u0915\u0930 API \u0915\u0947 \u092e\u093e\u0927\u094d\u092f\u092e \u0938\u0947 Webpage \u092a\u0930 Display \u0915\u0930\u0947\u0902\u0917\u0947 \u0964 <\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2.1 Make a Directory named ApiProject<\/h3>\n\n\n\n<p>\u0938\u092c\u0938\u0947 \u092a\u0939\u0932\u0947 \u0906\u092a ApiProject \u0928\u0947\u092e \u0938\u0947 \u090f\u0915 Folder \u092c\u0928\u093e \u0932\u0947 \u0964 <\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2022\/06\/image.png?resize=171%2C45&#038;ssl=1\" alt=\"\" class=\"wp-image-8336\" width=\"171\" height=\"45\" srcset=\"https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2022\/06\/image.png?w=171&amp;ssl=1 171w, https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2022\/06\/image.png?resize=150%2C39&amp;ssl=1 150w\" sizes=\"auto, (max-width: 171px) 100vw, 171px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"block-cb3fd1de-338d-48ae-ab01-256c45c0c8fb\">2.2 Open Directory Within Visual Code<\/h3>\n\n\n\n<p>Folder \u092c\u0928\u093e\u0928\u0947 \u0915\u0947 \u092c\u093e\u0926 \u0906\u092a Folder open \u0915\u0930\u0947 \u0914\u0930 \u0909\u0938 Folder \u092e\u0947 Right Click \u0915\u0930 \u0906\u092a  Visual Code \u092e\u0947 Open \u0915\u0930\u0947 \u0964 <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"640\" height=\"345\" src=\"https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2022\/06\/image-1.png?resize=640%2C345&#038;ssl=1\" alt=\"\" class=\"wp-image-8339\" srcset=\"https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2022\/06\/image-1.png?w=773&amp;ssl=1 773w, https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2022\/06\/image-1.png?resize=300%2C162&amp;ssl=1 300w, https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2022\/06\/image-1.png?resize=768%2C414&amp;ssl=1 768w, https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2022\/06\/image-1.png?resize=150%2C81&amp;ssl=1 150w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"block-cb3fd1de-338d-48ae-ab01-256c45c0c8fb\"><br>2.3 Open Terminal<\/h3>\n\n\n\n<p>After Open Visual Code, Click Terminal -&gt; New Terminal<\/p>\n\n\n\n<p>Terminal Menu \u092a\u0930 Click \u0915\u0930 \u0906\u092a New Terminal Option select \u0915\u0930\u0947 \u0964 <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"586\" height=\"68\" src=\"https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2022\/06\/image-2.png?resize=586%2C68&#038;ssl=1\" alt=\"\" class=\"wp-image-8340\" srcset=\"https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2022\/06\/image-2.png?w=586&amp;ssl=1 586w, https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2022\/06\/image-2.png?resize=300%2C35&amp;ssl=1 300w, https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2022\/06\/image-2.png?resize=150%2C17&amp;ssl=1 150w\" sizes=\"auto, (max-width: 586px) 100vw, 586px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"block-cb3fd1de-338d-48ae-ab01-256c45c0c8fb\"><br>2.4 Make Package JSON using (npm inti -y)<\/h3>\n\n\n\n<p>Project Folder \u092c\u0928\u093e\u0928\u0947 \u0915\u0947 \u092c\u093e\u0926 \u0939\u092e\u0947 Package\u0964 json file \u092c\u0928\u093e\u0928\u093e \u0939\u094b\u0924\u0940 \u0939\u0948\u0902 , \u092f\u0926\u093f \u0906\u092a npm inti -y Command \u0932\u093f\u0916\u0947\u0902\u0917\u0947 \u0924\u092c \u0906\u092a\u0915\u0947 Folder \u092e\u0947 package.json  file \u092c\u0928 \u091a\u0941\u0915\u0940 \u0939\u094b\u0917\u0940 \u0964  <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"javascript\" class=\"language-javascript\">npm init -y<\/code><\/pre>\n\n\n\n<p>\u092b\u093e\u0907\u0932 \u092c\u0928\u0928\u0947 \u0915\u0947 \u092c\u093e\u0926 \u0906\u092a\u0915\u094b \u0915\u0941\u091b \u0907\u0938 \u0924\u0930\u0939 \u0938\u0947 \u0926\u093f\u0916\u093e\u0908 \u0926\u0947\u0917\u0940 \u0964 \u0907\u0938\u092e\u0947 \u0906\u092a\u0915\u094b &#8220;type&#8221;:&#8221;module&#8221;, add \u0915\u0930\u0928\u093e \u0939\u094b\u0917\u093e, add \u0915\u0930\u0928\u0947 \u0915\u0947 \u092c\u093e\u0926 package.json \u0915\u0941\u091b \u0907\u0938 \u0924\u0930\u0939 \u0938\u0947 \u0926\u093f\u0916\u093e\u0908 \u0926\u0947\u0917\u0940    <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"json\" class=\"language-json\">{\n  \"name\": \"apiproject\",\n  \"version\": \"1.0.0\",\n  \"description\": \"\",\n  \"type\": \"module\",  \n  \"main\": \"index.js\",\n  \"scripts\": {\n    \"test\": \"echo \\\"Error: no test specified\\\" &amp;&amp; exit 1\"\n  },\n  \"keywords\": [],\n  \"author\": \"\",\n  \"license\": \"ISC\", \n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"block-cb3fd1de-338d-48ae-ab01-256c45c0c8fb\"><br>2.5 Install Dependency using (npm i express mysql2 sequelize cors)<\/h3>\n\n\n\n<p>\u0905\u092c project \u092e\u0947 \u091c\u094b \u092d\u0940 \u0939\u092e\u0947 dependency \u0932\u0917\u0947\u0917\u0940 \u0909\u0928\u094d\u0939\u0947 \u0939\u092e \u0928\u093f\u092e\u094d\u0928 command \u0938\u0947 install \u0915\u0930 \u0932\u0947\u0902\u0917\u0947 \u0964 \u092f\u0939 \u092a\u0930 \u0939\u092e\u0928\u0947 \u090f\u0915 \u0939\u0940 Command \u092e\u0947 \u0939\u092e\u0947 \u091c\u093f\u0924\u0928\u0940 \u092d\u0940 Dependency \u0915\u093e \u0909\u092a\u092f\u094b\u0917 \u0939\u094b \u0930\u0939\u093e \u0939\u0948\u0902 \u0938\u092d\u0940 \u0915\u094b \u0932\u093f\u0916\u093e \u0939\u0948\u0902 \u091c\u093f\u0938\u0938\u0947 \u0915\u0940 \u092f\u0939 \u090f\u0915 \u090f\u0915 \u0915\u0930 Install \u0939\u094b \u091c\u093e\u090f\u0917\u0940 \u0964 <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">npm i mysql2 sequelize express cors<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>mysql2 :<\/strong> \u092f\u0939\u093e MySQL \u0938\u0947 Connection \u0915\u0930\u0928\u0947 \u0915\u0947 \u0932\u093f\u090f \u0939\u092e\u0947 mysql2 dependency  \u0915\u093e \u0909\u092a\u092f\u094b\u0917 \u0915\u0930\u0928\u093e \u0939\u094b\u0924\u093e \u0939\u0948\u0902 \u0964 <\/li><li><strong>sequelize :<\/strong> \u0907\u0938 dependecy \u0938\u0947 \u0906\u092a\u0915\u094b \u092c\u0939\u0941\u0924 \u0939\u0940 \u0915\u092e coding API \u0932\u093f\u0916\u093e \u091c\u093e\u0924\u0940 \u0939\u0948\u0902 \u0964 \u0915\u0947\u0935\u0932 \u0906\u092a\u0915\u094b Table \u0914\u0930 \u0909\u0938\u0915\u0947 Columns define \u0915\u0930\u0928\u0947 \u0939\u094b\u0924\u0947 \u0939\u0948\u0902 \u0914\u0930 \u0905\u0932\u0917 \u0938\u0947 \u0915\u094b\u0908 Select, Insert, Update, Delete \u0928\u0939\u0940\u0902 \u0932\u093f\u0916\u0928\u093e \u0939\u094b\u0924\u0940 \u0939\u0948\u0902 \u0964    <\/li><li><strong>Express :<\/strong> \u0907\u0938 dependecy \u0915\u093e \u0909\u092a\u092f\u094b\u0917 \u0915\u0930\u0928\u093e \u0938\u0947 \u0939\u092e \u091c\u094b URL Based Page linking \u0915\u0930\u0924\u0947 \u0939\u0948\u0902 \u0909\u0938\u0915\u094b \u092c\u0939\u0941\u0924 \u0915\u092e Code \u092e\u0947 Manage \u0915\u0930\u0928\u0947 \u0915\u093e \u0915\u093e\u0930\u094d\u092f \u0915\u093f\u092f\u093e \u091c\u093e\u0924\u093e \u0939\u0948, Project Coding \u0938\u092e\u091d\u0928\u0947 \u092e\u0947 \u092d\u0940 \u0906\u0938\u093e\u0928 \u0939\u094b\u0924\u0940 \u0939\u0948\u0902 \u0964 <\/li><li><strong>Cors :<\/strong>  Express \u0915\u093e \u0909\u092a\u092f\u094b\u0917 \u0915\u0930\u0924\u0947 \u0938\u092e\u092f \u0939\u092e Cors \u0915\u093e \u0909\u092a\u092f\u094b\u0917 \u0915\u0930\u0924\u0947 \u0939\u0948\u0902 \u091c\u094b \u0915\u0940 \u0939\u092e\u0947 URL \u0914\u0930 Express \u0915\u094b Communicate \u0915\u0930\u0928\u0947 \u092e\u0947 Help \u0915\u0930\u0924\u093e \u0939\u0948\u0902\u0964 <\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"block-cb3fd1de-338d-48ae-ab01-256c45c0c8fb\">2.6 Understand Project Structure <\/h3>\n\n\n\n<p>\u0907\u0938 Project \u0915\u093e File Structure \u0915\u0941\u091b \u0907\u0938 \u092a\u094d\u0930\u0915\u093e\u0930 \u0939\u094b\u0917\u093e \u0964 <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"264\" height=\"228\" src=\"https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2022\/06\/image-3.png?resize=264%2C228&#038;ssl=1\" alt=\"\" class=\"wp-image-8345\" srcset=\"https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2022\/06\/image-3.png?w=264&amp;ssl=1 264w, https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2022\/06\/image-3.png?resize=150%2C130&amp;ssl=1 150w\" sizes=\"auto, (max-width: 264px) 100vw, 264px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Common Folder : <\/strong>\u0907\u0938 folder \u092e\u0947 \u091c\u094b \u092d\u0940 \u0939\u092e\u0947 common Files \u0932\u0917\u0947\u0917\u0940 \u0909\u0928\u0915\u094b \u0939\u092e \u0930\u0916\u0947\u0902\u0917\u0947 \u091c\u0948\u0938\u0947 \u0915\u0940 database connection \u0938\u0947 \u0938\u0902\u092c\u0902\u0927\u093f\u0924 file \u0939\u092e\u0928\u0947 \u0907\u0938 folder \u092e\u0947 \u092c\u0928\u093e\u0908 \u0939\u0948\u0902 \u0964 <\/li><li><strong>MyPages Folder : <\/strong>\u0905\u092d\u0940 \u0939\u092e\u0928\u0947 example \u0915\u0947 \u0932\u093f\u090f Student \u0915\u093e data \u0926\u093f\u0916\u093e\u092f\u093e \u0939\u0948\u0902 \u0907\u0938\u0932\u093f\u090f student.js file \u0907\u0938 folder \u092e\u0947 \u092c\u0928\u093e\u0908 \u0939\u0948\u0902 \u0906\u092a\u0915\u094b database \u0938\u0947 \u091c\u093f\u0928 \u092d\u0940 table \u0915\u093e data \u0926\u093f\u0916\u093e\u0928\u093e \u0939\u0948\u0902 \u0906\u092a\u0915\u094b \u0909\u0928\u0915\u0940 \u090f\u0915 js file \u092c\u0928\u093e\u0928\u093e \u0939\u094b\u0917\u0940 \u0964   <\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"block-cb3fd1de-338d-48ae-ab01-256c45c0c8fb\"><br>2.7 Database Connection using database.js<\/h3>\n\n\n\n<p>\u0907\u0938 File \u0938\u0947 \u0939\u092e Database \u0915\u094b Connect \u0915\u0930\u0947\u0902\u0917\u0947 \u0964 <\/p>\n\n\n\n<pre title=\"common\\database.js\" class=\"wp-block-code\"><code lang=\"javascript\" class=\"language-javascript\">import { Sequelize } from \"sequelize\";\n\nconst db = new Sequelize('MyDB', 'root', '', {\n    host: \"localhost\",\n    dialect: \"mysql\"\n});\n\nexport default db;\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"block-cb3fd1de-338d-48ae-ab01-256c45c0c8fb\"><br>2.8 Connect Table using Student.js<\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Define Table :<\/strong> \u0907\u0938 \u092b\u093e\u0907\u0932 \u092e\u0947 \u0939\u092e Student Table \u0938\u0947 Data Get \u0915\u0930 \u0930\u0939\u0947 \u0939\u0948\u0902 \u0907\u0938\u0932\u093f\u090f \u0939\u092e\u0928\u0947 Student object \u092c\u0928\u093e \u0915\u0930 \u0909\u0938\u092e\u0947 column define \u0915\u093f\u090f \u0939\u0948\u0902 \u091c\u094b \u0915\u0940 \u0939\u092e\u093e\u0930\u0940 \u091f\u0947\u092c\u0932 \u092e\u0947 \u0925\u0947 \u0964 \u0910\u0938\u093e \u0915\u0930\u0928\u0947 \u0938\u0947 \u0939\u092e\u0947 \u092f\u0939 Benefit \u0939\u094b\u0917\u0940 \u0915\u0940 \u091c\u092c \u092d\u0940 \u0939\u092e\u0947 \u0907\u0938 Table Data Insert \u0915\u0930\u0928\u093e \u0939\u094b update \u0915\u0930\u0928\u093e \u0939\u094b \u092f\u093e Data \u0915\u094b delete \u0915\u0930\u0928\u093e \u0939\u094b \u0924\u092c \u0905\u0932\u0917 \u0938\u0947 \u0915\u094b\u0908 Code \u0928\u0939\u0940\u0902 \u0932\u093f\u0916\u0928\u093e \u0939\u094b\u0917\u093e , \u092f\u0939 Student object Mange \u0915\u0930 \u0932\u0947\u0917\u093e\u0964 <\/li><li><strong>Define Methods :<\/strong> \u0938\u093e\u0925 \u092e\u0947 \u0939\u092e\u0928\u0947 \u0907\u0938\u092e\u0947 Data \u0915\u094b Get \u0915\u0930\u0928\u093e \u0915\u0947 \u0932\u093f\u090f \u090f\u0915 Method GetStudentData \u092c\u0928\u093e\u0908 \u0939\u0948\u0902 \u091c\u093f\u0938\u0938\u0947 \u0915\u0940 \u0939\u092e Data \u0915\u094b json data \u092e\u0947 \u092a\u094d\u0930\u093e\u092a\u094d\u0924 \u0915\u0930 \u0932\u0947\u0902\u0917\u0947 \u0964 <\/li><\/ul>\n\n\n\n<pre title=\"MyPages\/Student.js\" class=\"wp-block-code\"><code lang=\"javascript\" class=\"language-javascript\">import { Sequelize } from \"sequelize\";\nimport db from \"..\/common\/database.js\";\n \nconst { DataTypes } = Sequelize;\n \n\/* 1. Define Table *\/\nexport const Student = db.define('studentmst',{\n    stud_nm:{ type: DataTypes.STRING },\n    stud_class:{type: DataTypes.DOUBLE }\n},{\n    freezeTableName: true\n});\n \n\n\/* 2. Define Methods *\/\nexport const GetStudentData = async (req, res) =&gt; {\n    try {\n        \/\/For All Columns\n        \/\/ Required createdAt, updatedAt Columns in Table when Show All Columns\n        \/*const MyData = await Student.findAll(); *\/\n\n\n        \/\/For Selected Columns\n        const MyData = await Student.findAll({attributes: ['stud_nm', 'stud_class']});\n\n        res.json(MyData);\n    } catch (error) {\n        res.json({ message: error.message });\n    }  \n}\n\n<\/code><\/pre>\n\n\n\n<p>\u0906\u092a\u0915\u0947 \u092a\u093e\u0938 data \u0915\u094b get \u0915\u0930\u0928\u0947 \u0915\u0947 \u0926\u094b \u0924\u0930\u0940\u0915\u0947 \u0939\u0948\u0902 <\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>For All Columns<\/strong>  : \u0907\u0938\u092e\u0947 \u0906\u092a\u0915\u094b \u091f\u0947\u092c\u0932 \u092e\u0947 \u091c\u0940\u0924\u0928\u0947 \u092d\u0940 \u0915\u0949\u0932\u092e \u0939\u094b\u0902\u0917\u0947 \u0938\u092d\u0940 \u0906 \u091c\u093e\u090f\u0902\u0917\u0947 , \u091c\u092c \u0939\u092e Sequelize \u0915\u093e \u0909\u092a\u092f\u094b\u0917 \u0915\u0930\u0924\u0947 \u0939\u0948 \u0939\u0948\u0902 \u0939\u092e\u0947 \u0926\u094b column \u0939\u0930 \u091f\u0947\u092c\u0932 \u092e\u0947 \u092c\u0928\u093e\u0928\u0947 \u0939\u0940 \u0939\u094b\u0924\u0947 \u0939\u0948\u0902 \u0964 createdAt, updatedAt<\/li><li><strong>For Selected Columns<\/strong> : \u0907\u0938 method \u092e\u0947 \u0906\u092a\u0915\u094b attributes \u092e\u0947 column \u0915\u0947 \u0928\u093e\u092e \u0926\u0947\u0928\u0947 \u0939\u094b\u0924\u0947 \u0939\u0948\u0902 \u0935\u0939\u0940 \u0915\u0949\u0932\u092e json \u092e\u0947 \u0926\u093f\u0916\u093e\u0908 \u0926\u0947\u0902\u0917\u0947 \u0964 <\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"block-cb3fd1de-338d-48ae-ab01-256c45c0c8fb\">2.9 Routing using Index.js<\/h3>\n\n\n\n<p>\u092f\u0939 Page Entry Point \u0939\u094b\u0924\u093e \u0939\u0948\u0902, \u0907\u0938\u0938\u0947 \u0939\u092e \/student \u0938\u0947 \u0939\u092e\u0928\u0947 \u091c\u094b Method GetStudentData \u092c\u0928\u093e\u0908 \u0925\u0940 \u0909\u0938\u0947 Route \u0915\u0930\u0947\u0902\u0917\u0947 \u0964 <\/p>\n\n\n\n<pre title=\"index.js\" class=\"wp-block-code\"><code lang=\"javascript\" class=\"language-javascript\">import express from \"express\";\nimport db from \".\/common\/database.js\";\nimport cors from \"cors\";\nimport { GetStudentData } from \".\/MyPages\/Student.js\";\n\nconst app = express();\n \ntry {\n    await db.authenticate();\n    console.log('Database Connected...');\n} catch (error) {\n    console.error('Database Connection Error:', error);\n}\n \napp.use(cors());\napp.use(express.json());\napp.use('\/student', GetStudentData);\n\n\n\napp.listen(5000, () =&gt; console.log('Server Port 5000'));<\/code><\/pre>\n\n\n\n<p>\u0906\u092a \u091c\u0940\u0924\u0928\u0947 \u092d\u0940 Database \u092e\u0947 \u091f\u0947\u092c\u0932 \u092c\u0928\u093e\u090f\u0902\u0917\u0947 \u0909\u0928\u0915\u0940 \u090f\u0915 js file MyPages Folder \u092e\u0947 \u092c\u0928\u093e\u090f\u0902\u0917\u0947 \u0914\u0930 js file \u092e\u0947 \u091c\u094b Method \u092c\u0928\u093e\u090f\u0902\u0917\u0947 \u0909\u0928\u0915\u094b \u0906\u092a \u092f\u0902\u0939\u093e \u092a\u0930 app.use \u0915\u093e \u0909\u092a\u092f\u094b\u0917 \u0915\u0930 route \u0915\u0930 \u0938\u0915\u0947\u0902\u0917\u0947 \u0964   <\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"block-cb3fd1de-338d-48ae-ab01-256c45c0c8fb\"><br>2.10 Run Server<\/h3>\n\n\n\n<p>\u0907\u0938\u0915\u0947 \u092c\u093e\u0926 \u0906\u092a\u0915\u094b Terminal \u092a\u0930 node index type \u0915\u0930\u0928\u093e \u0939\u0948\u0902\u0964 <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">node index<\/code><\/pre>\n\n\n\n<p>\u0909\u092a\u0930\u094b\u0915\u094d\u0924 Command \u0915\u0947 \u092c\u093e\u0926 \u092f\u0926\u093f project \u092e\u0947 \u0915\u094b\u0908 \u092d\u0940 \u090f\u0930\u0930 \u0928\u0939\u0940\u0902 \u0939\u0941\u0908 \u0924\u094b \u0906\u092a\u0915\u094b \u0915\u0941\u091b \u0928\u093f\u092e\u094d\u0928 \u0924\u0930\u0939 \u0915\u093e message \u0926\u093f\u0916\u093e\u0908 \u0926\u0947\u0928\u0947 \u0932\u0917\u0947\u0917\u093e , \u092f\u0926\u093f \u092f\u0939 message \u0906 \u091c\u093e\u0924\u093e \u0939\u0948\u0902 \u092f\u093e\u0928\u093f \u0915\u0940 \u0906\u092a\u0915\u093e server \u092c\u0928 \u091a\u0941\u0915\u093e \u0939\u0948\u0902 \u0964 <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"640\" height=\"133\" src=\"https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2022\/06\/image-4.png?resize=640%2C133&#038;ssl=1\" alt=\"\" class=\"wp-image-8352\" srcset=\"https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2022\/06\/image-4.png?w=723&amp;ssl=1 723w, https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2022\/06\/image-4.png?resize=300%2C62&amp;ssl=1 300w, https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2022\/06\/image-4.png?resize=150%2C31&amp;ssl=1 150w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/figure>\n\n\n\n<p>\u0905\u092c \u0906\u092a\u0915\u094b Browser \u092a\u0930 data \u0926\u0947\u0916\u0928\u0947 \u0915\u0947 \u0932\u093f\u090f \u0928\u093f\u092e\u094d\u0928 URL Type \u0915\u0930\u0928\u093e \u0939\u094b\u0917\u0940 <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">http:\/\/localhost:5000\/student<\/code><\/pre>\n\n\n\n<p>\u091c\u092c \u0906\u092a Browser \u092a\u0930 URL  Type \u0915\u0930 Enter \u0915\u0930\u0947\u0902\u0917\u0947 \u0924\u094b \u0906\u092a\u0915\u094b \u0915\u0941\u091b \u0907\u0938 \u092a\u094d\u0930\u0915\u093e\u0930 \u0938\u0947 Response \u0906\u090f\u0917\u093e <\/p>\n\n\n\n<pre title=\"Output JSON\" class=\"wp-block-code\"><code lang=\"json\" class=\"language-json\">[\n{\"stud_nm\":\"Sandip Nigam\",\"stud_class\":\"12th\"},\n{\"stud_nm\":\"Rishabh Sharma\",\"stud_class\":\"11th\"},\n{\"stud_nm\":\"Rakesh Mali\",\"stud_class\":\"12th\"},\n{\"stud_nm\":\"Vishal Garg\",\"stud_class\":\"12th\"}\n]<\/code><\/pre>\n\n\n\n<p>\u0905\u092c \u0907\u0938 Response \u0915\u094b \u0906\u092a \u0915\u093f\u0938\u0940 \u0905\u0928\u094d\u092f Project \u092e\u0947 Get \u0915\u0930 \u0938\u0915\u0924\u0947 \u0939\u0948\u0902 \u0964 Next Article \u092e\u0947 \u0906\u092a\u0915\u094b \u092e\u0947 \u0909\u0938\u0915\u093e \u092d\u0940 Example \u092c\u0928\u093e \u0915\u0930 \u092c\u0924\u093e\u090a\u0901\u0917\u093e \u0964 <\/p>\n\n\n\n<p>\u0906\u092a\u0915\u094b \u092f\u0939 Article Node React Express MySQL Sequelize \u0915\u0948\u0938\u093e \u0932\u0917\u093e \u092e\u0941\u091d\u0947 \u091c\u0930\u0942\u0930 \u092c\u0924\u093e\u090f \u0964 \u0915\u093f\u0938\u0940 \u092d\u0940 \u092a\u094d\u0930\u0915\u093e\u0930 \u0915\u093e Doubt \u0939\u094b \u0924\u094b \u0906\u092a Comment \u0915\u0930\u0947 \u0964 <\/p>\n\n\n\n<p>\u0905\u092a\u0928\u093e \u0915\u0940\u092e\u0924\u0940 \u0938\u092e\u092f \u0926\u0947\u0928\u0947 \u0915\u0947 \u0932\u093f\u090f \u0927\u0928\u094d\u092f\u0935\u093e\u0926 \u0964 <\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">FAQ<\/h2>\n\n\n<div id=\"rank-math-faq\" class=\"rank-math-block\">\n<div class=\"rank-math-list \">\n<div id=\"faq-question-1655813817083\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">What is Sequelize MySQL?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Sequelize MySQL \u0915\u0947 Promised Based ORM \u0939\u0948\u0902 , \u091c\u093f\u0938\u0915\u093e \u0909\u092a\u092f\u094b\u0917 \u0915\u0930 \u0939\u092e MySQL \u0914\u0930 \u0905\u0928\u094d\u092f Database \u0938\u0947 selected Table \u092e\u0947 Data Select, Insert, Update, Delete \u0906\u0926\u093f \u0915\u0930\u0928\u0947 \u092e\u0947 \u0909\u092a\u092f\u094b\u0917 \u0915\u0930\u0924\u0947 \u0939\u0948\u0902, \u0907\u0938\u0915\u093e \u0938\u092c\u0938\u0947 \u092c\u095c\u093e \u092b\u093e\u092f\u0926\u093e \u092f\u0939 \u0939\u094b\u0924\u093e \u0939\u0948\u0902 \u0915\u0940 \u0906\u092a\u0915\u0947 \u0915\u0947\u0935\u0932 \u090f\u0915 \u092c\u093e\u0930 Table \u0915\u0947 \u0928\u093e\u092e \u0915\u0947 \u0938\u093e\u0925 Column Define \u0915\u0930\u0928\u093e \u0939\u094b\u0924\u0947 \u0939\u0948\u0902 \u0914\u0930 \u0906\u092a\u0915\u094b \u0915\u0939\u0940 \u092a\u0930 \u092d\u0940 \u0905\u0932\u0917 &#8211; \u0905\u0932\u0917 INSERT, UPDATE query \u0928\u0939\u0940\u0902 \u0932\u093f\u0916\u0928\u093e \u0939\u094b\u0924\u0940 \u0939\u0948\u0902 , \u092f\u0939 \u0916\u0941\u0926 \u0939\u0940 \u0909\u0928\u0915\u094b \u092c\u0928\u093e \u0915\u0930 \u0909\u092a\u092f\u094b\u0917 \u0915\u0930\u0924\u093e \u0939\u0948\u0902 , \u0907\u0938 \u0915\u093e\u0930\u0923 \u092c\u0939\u0941\u0924 \u0939\u0940 \u0915\u092e coding \u092e\u0947 \u0906\u092a \u0915\u093f\u0938\u0940 \u092d\u0940 Form \u0915\u0947 data \u0915\u094b \u091f\u0947\u092c\u0932 \u092e\u0947 Store \u0915\u0930 \u0938\u0915\u0924\u0947 \u0939\u0948\u0902 update \u0915\u0930 \u0938\u0915\u0924\u0947 \u0939\u0948\u0902, \u0921\u093f\u0932\u0940\u091f \u0915\u0930 \u0938\u0915\u0924\u0947 \u0939\u0948\u0902 \u0964    <\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"\u0939\u092e-\u0930-\u0905\u0928-\u092f-\u0906\u0930-\u091f-\u0915\u0932\"><strong>\u0939\u092e\u093e\u0930\u0947 \u0905\u0928\u094d\u092f \u0906\u0930\u094d\u091f\u093f\u0915\u0932<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/selfimagination.in\/tips\/mysql-function\/\">MySQL Function<\/a><\/li><li><a href=\"https:\/\/selfimagination.in\/tips\/mysql-stored-procedure\/\">MySQL Stored Procedure<\/a><\/li><li><a href=\"https:\/\/selfimagination.in\/tips\/get-post-method\/\">PHP Get \/Post Method \u0915\u0947 \u092c\u093e\u0930\u0947 \u092e\u0947\u0902 \u091c\u093e\u0928\u0947<\/a><\/li><li><a href=\"https:\/\/selfimagination.in\/tips\/php-math-function\/\">PHP Math Function \u0915\u0947 \u092c\u093e\u0930\u0947 \u092e\u0947\u0902 \u091c\u093e\u0928\u0947<\/a><\/li><li><a href=\"https:\/\/selfimagination.in\/tips\/learn-cpp-from-c\/\">C \u0938\u0947 C ++ \u0938\u0940\u0916\u0947 \u0938\u0930\u0932 \u0936\u092c\u094d\u0926\u094b\u0902 \u092e\u0947\u0902<\/a><\/li><li><a href=\"https:\/\/selfimagination.in\/tips\/php-variables\/\">PHP Variable \u0915\u0947 \u092c\u093e\u0930\u0947 \u092e\u0947\u0902 \u091c\u093e\u0928\u0947<\/a><\/li><li><a href=\"https:\/\/selfimagination.in\/tips\/arduino-control-structure\/\">Arduino Control Structure<\/a>\u00a0<\/li><li><a href=\"https:\/\/selfimagination.in\/tips\/c-union\/\">Union in C<\/a><\/li><li><a href=\"https:\/\/selfimagination.in\/tips\/c-pointer\/\">Declaration of Pointer in C<\/a><\/li><li><a href=\"https:\/\/selfimagination.in\/tips\/search-jquery\/\">jQuery Search Filter<\/a><\/li><li><a href=\"https:\/\/selfimagination.in\/tips\/mysql-table-create-alter-drop\/\">MySQL Create Table | Alter Table | Drop Table<\/a><\/li><li><a href=\"https:\/\/selfimagination.in\/tips\/api-using-node-react-express-mysql\/\">API Using NODE REACT EXPRESS MYSQL SEQUELIZE (For Backend OR Server Side)<\/a><\/li><li><a href=\"https:\/\/selfimagination.in\/tips\/cpanel\/\">CPANEL In Hindi<\/a><\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>This Aritcle for Create API Using Node React Express MySQL Sequelize, Creating a Local Server, Server Side API for MySQL Connection \u091c\u092c \u092d\u0940 \u0906\u092a\u0915\u094b React \u092e\u0947 Database \u0938\u0947 Connect \u0915\u0930 \u0915\u094b\u0908 \u092d\u0940 Project \u092c\u0928\u093e\u0928\u093e \u0939\u094b \u0924\u092c \u0906\u092a\u0915\u094b \u0938\u092c\u0938\u0947 \u092a\u0939\u0932\u0947 \u090f\u0915 API \u0915\u0947 \u0932\u093f\u090f \u090f\u0915 \u0905\u0932\u0917 Project \u092c\u0928\u093e\u0928\u093e \u0939\u094b\u0917\u093e \u0964 \u091c\u093f\u0938\u092e\u0947 \u0906\u092a SQL Logic \u0932\u093f\u0916 \u0909\u0928\u0915\u094b [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":8742,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-8335","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-other"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/i0.wp.com\/selfimagination.in\/tips\/wp-content\/uploads\/2022\/06\/api-using-node-react-express-mysql-sequelize.jpg?fit=1200%2C628&ssl=1","_links":{"self":[{"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/posts\/8335","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/comments?post=8335"}],"version-history":[{"count":129,"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/posts\/8335\/revisions"}],"predecessor-version":[{"id":8710,"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/posts\/8335\/revisions\/8710"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/media\/8742"}],"wp:attachment":[{"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/media?parent=8335"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/categories?post=8335"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/selfimagination.in\/tips\/wp-json\/wp\/v2\/tags?post=8335"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}