This should be a simple solution but when I Google it everyone seems to miss this. I want to send a simple json message/file to my index.html
Node.js code
const express = require('express');
const app = express();
const path = require('path');
const router = express.Router();
router.get('/',function(req,res){
res.setHeader('Access-Control-Allow-Origin', '*');
res.sendFile(path.join(__dirname+'/index.html'));
});
app.get('/index.html', function(req, res, next) {
res.json({ message: 'Hello World' });
});
app.use('/', router);
app.listen(process.env.port || 3000);
console.log('Running at Port 3000');
Now inside my javascript code I have
$.ajax({
url: 'http://localhost:3000/',
complete: function(data) {
console.log(data); <---------THIS IS WHERE I WANT THE JSON TO BE I
WANT TO LOG
IT
}
});
How come my Json message doesn't show up??? How can I get this data and console.log it. I appreciate any help I can get on this. I am using Express.