0

Can someone help me why default route is not working in my Mean App, But the next routing works

Here when I open http://localhost:3000 I am not able to see any output, But I have defined route in route.js which is working

   var express = require('express');
   var cors = require('cors');
   var bodyparser = require('body-parser');
   var mongoose = require('mongoose');
   var path = require('path');

    const port = 3000;

    app.get('/', function (req, res) {
        res.send('Test');
        console.log('Opened the root path');
    });

When I open the page with http://localhost:3000/main I am able to see the Output and also log written in the console

const express = require('express');
const router = express.Router();

router.get('/main', function (req, res, next) {
    res.send('This is the Admin Landing Page');
});

router.get('/install', function (req, res, next) {
    res.send('This is the Install Landing Page');
    console.log('Opened the Install  path');
});

module.exports = router;
Mahesh G
  • 1,226
  • 4
  • 30
  • 57

1 Answers1

0

It looks like you the code you pasted is the full version, and it's not runnable because:

  1. You did not declare app variable.
  2. You did not start the http server.

It's really hard to tell the root cause what's wrong of your code. Following codes works for me:

const express = require('express');
const port = 3000;

let app = express();

app.get('/', function (req, res) {
    res.send('Test');
    console.log('Opened the root path');
});

let server = require('http').createServer(app);
server.listen(port, function() {
    console.log('Server started');
});
Yu-Lin Chen
  • 559
  • 5
  • 12
  • But Is there anything wrong I am doing in my code Just wanted to understand what it's making not to run – Mahesh G Dec 25 '17 at 13:16
  • Sorry I didn't define entire code here , I had initialized the `app` and also started the HTTP server using `nodemon` – Mahesh G Dec 25 '17 at 13:28
  • No, I'm not getting any error and I feel that method is not calling at all because I am not getting anything in the console logs as well when I open `http://localhost:3000` I just see blank screen – Mahesh G Dec 25 '17 at 13:36
  • If you shutdown the server, you will get `404`, right? – Yu-Lin Chen Dec 25 '17 at 13:59