Create-Read-Update-Delete operations using Node.js, MySQL.
Software prerequisites:
- Node.js
- Joi
- Mysql
- Swagger
This is a Node.js module available through the npm registry.
Before installing, download and install Node.js. Node.js 0.10 or higher is required.
If this is a brand new project, make sure to create a package.json first with
the npm init command.
Installation is done using the
npm install command:
$ npm install expressThe quickest way to get started with express is to utilize the executable express(1) to generate an application as shown below:
Install the executable. The executable's major version will match Express's:
$ npm install -g express-generator@4Create the app:
$ express nodejs-mysql && cd nodejs-mysqlInstall dependencies:
$ npm installStart the server:
$ npm startView the website at: http://localhost:3000
Joi is an object schema description language and validator for JavaScript objects. Joi allows you to create blueprints or schemas for JavaScript objects to ensure validation of key information. To get started with joi, you must first install and add it as a dependency to your project:
Installation is done using the npm install command:
$ npm install @hapi/joijoi-date extensions for advance date rules.
$ npm install @hapi/joi-dateThis is a node.js driver for mysql.
Installation is done using the npm install command:
$ npm install mysqlSwagger UI Express module allows you to serve auto-generated swagger-ui generated API docs from express, based on a swagger.json file. The result is living documentation for your API hosted from your API server via a route.
$ npm install swagger-ui-express swagger-jsdocnodejs-mysql
|
|
|____app
| |____UserComponent
| |____user.controller.js
| |____user.model.js
| |____user.utility.js
| |____user.validator.js
|
|
|____bin
| |____www
|
|
|____config
| |____database.js
|
|
|____node_modules
|
|
|____public
| |____stylesheets
| | |__style.css
| |
| |____index.html
|
|
|____routes
| |____index.js
| |____users.js
|
|
|____app.js
|
|
|____package.json
create database TEST;
use TEST;
create table userinfo(
userInfoId int primary key auto_increment,
name varchar(50),
address varchar(50),
dateOfBirth date,
mobileNumber bigint
);
Run this project by this command :
npm installnpm startlocalhost:3000