0

I am using Expressjs and nodejs for accessing file and through that I am sending response to Angularjs. I am using json data to display the content in by browser. when I run the server, port is not displaying any message.

ExpressJS:

var express = require('express');
var config = require('./config');
var jsonserver = require('json-server');
var app = express();

app.use(express.static(__dirname + '/public'));

app.get('/contact', function(req,res) {
    if (res.sendFile(path.normalize(__dirname + '/public/contact.json'))) {
        console.log('Request is received');     
    } else {
        console.log('Error');
    } 
});

I don't where I Have gone wrong. Please let me know my mistake . Any help/advise greatly appreciated.

SRK
  • 163
  • 2
  • 18
  • 3
    are you using `path.normalize()` correctly? try this `if (res.sendFile(path.normalize( '/public/contact.json')) !== 'undefined')` – Satish Patel Oct 30 '17 at 11:25
  • Alright and should I include the normalize package or not ? – SRK Oct 30 '17 at 11:29
  • I got error stating that path must be absolute or specify root to res.sendFile @SatishPatel – SRK Oct 30 '17 at 11:35
  • you need to do this `res.sendFile(__dirname + '/public/contact.json')` – Satish Patel Oct 30 '17 at 11:52
  • @SatishPatel. Well i debugged my code and every thing is working well. But the problem is my data is not getting displayed in browser. Moreover i am getting the response properly – SRK Oct 30 '17 at 12:23

0 Answers0