title: Nodejs Server is Running and localhost didn’t send any data on express project
body: <p>I working on Building a shopping cart Using Node.js Express and mongodb, using this <a href="https://www.youtube.com/watch?v=GHNLWHGCBEc&amp;t=1167s" rel="nofollow noreferrer">tutorial</a>, and so far there is no problem, but now when i run the server, it shows '</p>
  
  <blockquote>
    <p>Server running on port 3000</p>
  </blockquote>
  
  <p>' But the problem is when I connect to localhost:3000 it shows, </p>
  
  <blockquote>
    <p>This page isn’t working localhost didn’t send any data.
    ERR_EMPTY_RESPONSE</p>
  </blockquote>
  
  <p>I check some error logs but didn't work. DB connection is also working, and DB has fetching data</p>
  
  <p>There is no error shown in the terminal, How to solve this</p>
  
  <p>my bin/www code</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>#!/usr/bin/env node
  
  /**
   * Module dependencies.
   */
  
  var app = require('../app');
  var debug = require('debug')('shopping-cart:server');
  var http = require('http');
  
  /**
   * Get port from environment and store in Express.
   */
  
  var port = normalizePort(process.env.PORT || '3000');
  app.set('port', port);
  
  /**
   * Create HTTP server.
   */
  
  var server = http.createServer(app);
  
  /**
   * Listen on provided port, on all network interfaces.
   */
  
  server.listen(port);
  server.on('error', onError);
  server.on('listening', onListening);
  
  /**
   * Normalize a port into a number, string, or false.
   */
  
  function normalizePort(val) {
    var port = parseInt(val, 10);
  
    if (isNaN(port)) {
      // named pipe
      return val;
    }
  
    if (port &gt;= 0) {
      // port number
      return port;
    }
  
    return false;
  }
  
  /**
   * Event listener for HTTP server "error" event.
   */
  
  function onError(error) {
    if (error.syscall !== 'listen') {
      throw error;
    }
  
    var bind = typeof port === 'string'
      ? 'Pipe ' + port
      : 'Port ' + port;
  
    // handle specific listen errors with friendly messages
    switch (error.code) {
      case 'EACCES':
        console.error(bind + ' requires elevated privileges');
        process.exit(1);
        break;
      case 'EADDRINUSE':
        console.error(bind + ' is already in use');
        process.exit(1);
        break;
      default:
        throw error;
    }
  }
  
  /**
   * Event listener for HTTP server "listening" event.
   */
  
  function onListening() {
    var addr = server.address();
    var bind = typeof addr === 'string'
      ? 'pipe ' + addr
      : 'port ' + addr.port;
    debug('Listening on ' + bind);
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>my app.js code </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var createError = require('http-errors');
  var express = require('express');
  var path = require('path');
  var cookieParser = require('cookie-parser');
  var logger = require('morgan');
  var indexRouter = require('./routes/index');
  var expressHbs = require('express-handlebars');
  var mongoose = require('mongoose');
  var session = require('express-session');
  var passport = require('passport');
  var flash = require('connect-flash');
  
  var app = express();
  
  mongoose.connect('mongodb://localhost:27017/shopping',{ useNewUrlParser: true });
  require('./config/passport');
  
  // view engine setup
  app.engine('.hbs',expressHbs({defaultLayout: 'layout', extname: '.hbs'}));
  app.set('view engine', '.hbs');
  
  app.use(logger('dev'));
  app.use(express.json());
  app.use(express.urlencoded({ extended: false }));
  app.use(cookieParser());
  app.use(session({secret: 'mysupersecert', resave: false, saveUninitialized: false}));
  app.use(flash);
  app.use(passport.initialize());
  app.use(passport.session());
  app.use(express.static(path.join(__dirname, 'public')));
  
  app.use('/', indexRouter);
  
  // 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>
  </div>
  </div>
  </p>
  
  <p>my index.js code </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var express = require('express');
  var router = express.Router();
  var csrf = require('csurf');
  var passport = require('passport');
  
  var Products = require('../models/product');
  
  var csurfProtection = csrf();
  router.use(csurfProtection);
  
  /* GET home page. */
  router.get('/', function(req, res, next) {
  
    Products.find(function (err, docs) {
      var productChunks = [];
      var chunkSize = 4;
      for (var i = 0; i &lt; docs.length; i += chunkSize) {
        productChunks.push(docs.slice(i, i + chunkSize))
      }
      res.render('shop/index', { title: 'Shopping Cart', products: productChunks });
  
    });
  });
  
  router.get('/user/signup', function (req, res, next) {
    res.render('user/signup',{csrfToken: req.csrfToken()})
  });
  
  router.post('/user/signup',passport.authenticate('local.signup', {
    successRedirect: 'user/profile',
    failureRedirect: 'user/signup',
    failureFlash: true
  
  }));
  
  router.get('user/profile', function (req, res, next) {
    res.render('user/profile')
  });
  
  module.exports = router;</code></pre>
  </div>
  </div>
  </p>
  
  <p>and my passport.js code</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var passport = require('passport');
  var User = require('../models/user');
  var LocalStrategy = require('passport-local').Strategy;
  
  passport.serializeUser(function (user, done) {
      done(null, user.id);
  });
  
  passport.deserializeUser(function (id, done) {
      User.findById(id,function (error, user) {
          done(err, user)
      })
  });
  
  passport.use('local.signup', new LocalStrategy({
      userNameFeild: 'email',
      passwordFeild: 'password',
      passReqToCallback: true
  }, function (req, email, password, done) {
      User.findOne({'email': email}, function (err, user) {
          if (err) {
              return done(err);
          }
          if (user) {
              return done(null, false, {message: 'Email Already in use'})
          }
          var newUser = User;
          newUser.email = email;
          newUser.password = newUser.encryptPassword(password);
          newUser.save(function (err, result) {
              if (err) {
                  return done(err);
              }
              return done(null, newUser);
          })
      })
  }));</code></pre>
  </div>
  </div>
  </p>
  
  <p>and my product.js code</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var mongoose = require('mongoose');
  var Schema = mongoose.Schema;
  
  var schema = new Schema({
      imagePath: {type: String, required: true},
      title: {type: String, required: true},
      description: {type: String, required: true},
      price: {type: Number, required: true}
  });
  
  module.exports = mongoose.model('product', schema);</code></pre>
  </div>
  </div>
  </p>
  
  <p>Please help me out</p>