Getting started with MEAN (Mysql, Express, Angular 6, Node) Part-3

This session, I am explaining about node server creation and table operations from MySQL database using sequelize models.

First, initialize Node using below command and fill the required details.

npm init

npm intilization.png

now create index.js (mentioned in entry point) file and paste below code.

//======== Import Required Files ===============
var express = require(‘express’);
var bodyparser = require(‘body-parser’);
var cors = require(‘cors’);
var jwt = require(‘jsonwebtoken’);
//============ Create Express app and initialize to app variable ========
var app = express();
// ============= initialize cros ==============
//=========== set port ================
app.set(‘port’,process.env.port || 3000 );
//========= initialize body parser ==========
//=========== Start Code Here ====================
    res.send({‘status’:true,’msg’:”Server Started.”});
//============== Code Ends Here ===================
//====== Start Server ===================
    console.log(‘Server Created in ‘+app.get(‘port’)+”Port”);
Run node server using below command and see your results in http://localhost:3000/
node index.js
node server.png

Insert some dummy data in your database tables. Then get the inserted data using sequelize.

if we want to get the data first include the users model.

var user = require(‘./models’).user;
var roles = require(‘./models’).roles;

Then place the below code and get output in http://localhost:3000/get-users. More details regarding models, go through this link (Click Here)

   user.findAll({ include: [{model:roles} ] }).then(users=> {

So you can insert user using below code(using postman you can add user details).‘/create-user’,(req,res)=>{
   var user_data=req.body;

Thank you, guys. In the next session, I will explain the connections between angular 6 and node.

Git Links:

Front End:


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create your website with
Get started
<span>%d</span> bloggers like this: