title: How to call smart contract from nodejs app with web3
body: <p>I have created a complete NODEJS app with routes and MySQL database and it listens on localhost:3000. And I have written a smart contract and tested it on remix online IDE.</p>
  
  <p>smart contract:</p>
  
  <pre><code>pragma solidity ^0.4.11;
  
  contract Hello {
       string name;
       function getName() constant returns(string){
            return name;
       }
       function setName(string n) {
            name = n;
       }
  }
  </code></pre>
  
  <p>My app.js:</p>
  
  <pre><code>let createError = require('http-errors');
  let express = require('express');
  let path = require('path');
  let cookieParser = require('cookie-parser');
  let bodyParser = require('body-parser');
  let logger = require('morgan');
  let passport = require('passport');
  let md5 = require('md5');
  let LocalStrategy = require("passport-local");
  let methodOverride = require("method-override");
  let app = express();
  let connection = require('./database');
  let indexRouter = require('./routes/index');
  let adminRouter = require('./routes/admin');
  let studentRouter = require('./routes/student');
  
  
  
  app.use(bodyParser.urlencoded({extended: true}));
  app.use(methodOverride("_method"));
  
  
  app.use(function(req, res, next) {
      //make available inside our template
      res.locals.currentUser = req.user;
      //important: move to the code that handles the route
      next();
  });
  
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({extended: false}));
  app.use(cookieParser());
  
  // view engine setup
  app.set('views', path.join(__dirname, 'views'));
  app.set('view engine', 'ejs');
  
  app.use(logger('dev'));
  app.use(express.json());
  app.use(express.urlencoded({ extended: false }));
  app.use(cookieParser());
  app.use(express.static(path.join(__dirname, 'public')));
  
  app.use('/', indexRouter);
  app.use('/student', studentRouter);
  app.use('/admin', adminRouter);
  
  
  // catch 404 and forward to error handler
  app.use(function(req, res, next) {
    next(createError(404));
  });
  
  // error handler
  app.use(function(err, req, res, next) {
    // set locals, only providing error in development
    res.locals.message = err.message;
    res.locals.error = req.app.get('env') === 'development' ? err : {};
  
    // render the error page
    res.status(err.status || 500);
    res.render('error');
  });
  
  module.exports = app;
  </code></pre>
  
  <p>My admin.js</p>
  
  <pre><code>var express = require('express');
  var router = express.Router();
  let connection = require('../database');
  let md5 = require('md5');
  
  // gets admin page
  router.get('/', function(req, res, next) {
      console.log("----------------------------IN ADMIN ROUTER");
  
  
      let queryString = "SELECT * FROM `semester` WHERE status =1 ;";
  
              connection.query(queryString, function (err, result) {
  
                  if (err) {
  
                      res.render('admin/admin', {title: 'admin', bool: 0, data: " "});
                  }
                  if(result){
  
                      res.render('admin/admin', { title: 'admin', bool: 1 , data: result });
                  }
                  else{
                      res.render('admin/admin', { title: 'admin', bool :0 , data: " " });
                  }
  
              });
  
  
  
  
  
  });
  
  router.get('/profile', function(req, res, next) {
  
      res.render('admin/profile', { title: 'Profile' });
  });
  
  router.get('/viewStudentRecord', function(req, res, next) {
  
      res.render('admin/viewStudentRecord', { title: 'View student record', bool: 0, data: " " });
  });
  </code></pre>
  
  <p>Now I want to call smart contract in admin.js
  I have seen examples of using smart contracts from nodejs but that whole app is only dedicated to smart contract and they are single page app.</p>
  
  <p>ps. I have installed GANACHE, METAMASK, WEB3</p>