GithubHelp home page GithubHelp logo

architpatel25 / crud-operation-using-nodejs-expressjs-mysql Goto Github PK

View Code? Open in Web Editor NEW

This project forked from learninfinity/crud-operation-using-nodejs-expressjs-mysql

0.0 1.0 0.0 6 KB

CRUD Operation using NodeJS ExpressJS MySQL

JavaScript 31.28% HTML 51.89% TSQL 16.82%

crud-operation-using-nodejs-expressjs-mysql's Introduction


| CRUD Operation using NodeJS / ExpressJS / MySQL |

Step 1 : install nodejs in your system and run follwoing comment npm init

Step 2 : Install Requred packages using NPM

		npm install --save express mysql body-parser ejs
		npm install -g nodemon (optional - used to run app.js automatically while any file content changes)

Step 3 : Add follwoing code in app.js

		const path = require('path');
		const express = require('express');
		const ejs = require('ejs');
		const bodyParser = require('body-parser');
		const mysql = require('mysql');
		const app = express();

		// Server Listening
		app.listen(3000, () => {
			console.log('Server is running at port 3000');
		});
		
		nodemon app (OR) npm start

Step 4 : Create Database Connection

		const mysql=require('mysql');
		
		const connection=mysql.createConnection({
		  host:'localhost',
		  user:'root',
		  password:'',
		  database:'node_crud'
		});
		
		connection.connect(function(error){
		  if(!!error) console.log(error);
		  else console.log('Database Connected!');
		}); 

Setp 5 : Define view engin with ejs / public path / view files path / bodyParser

		//set views file
		app.set('views',path.join(__dirname,'views'));
		
		//set view engine
		app.set('view engine', 'ejs');
		app.use(bodyParser.json());
		app.use(bodyParser.urlencoded({ extended: false }));

Setp 6 : Define index path with '/' and HTML file

		//route for user index page
		app.get('/',(req, res) => {
			res.render('user_index', {
				title: 'CRUD Operation using NodeJS / ExpressJS / MySQL '
			});
		});

Setp 7 : Run a server and check with Browser

		npm start (OR) nodemon app

		http://localhost:3000/

Step 8 : Get value from database and show in HTML table using ExpressJS / MySQL

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.