I need to bulid web server with two file activated (student.js) and active (index.js) that I call to a function from the index.js and want to get JSON from the student.js.
I created an outer json that holds all the details of the student and I want to print the JSON to my localhost.
I receive an error when I run it on localhost:
Cannot GET /getAllExcellenceStudent
var express=require('express');
var app=express();
var port=process.env.PORT || 3000;
var student=require('./student');
var stud=require('./students');
student.AllExcellenceStudent;
app.listen(port);
console.log('listening on port'+port);
var express=require('express');
var app=express();
var stud=require('./student');
module.exports = function AllExcellenceStudent() {
app.get('/getAllExcellenceStudent/', function(req, res) {
res.json.parse({name:'adi'});
})
};
{
"students": [
{ "name": "John", "grade": "90", "year": "2005", "coures": "math" },
{ "name": "Anna", "grade": "80", "year": "2000", "coures": "sport" },
{ "name": "Peter", "grade": "75", "year": "2005", "coures": "math" },
{ "name": "ron", "grade": "70", "year": "2000", "coures": "computer" },
{ "name": "mor", "grade": "85", "year": "2005", "coures": "computer" }
]
}
You need to pass your app object to your student and students module:
index.js:
var express=require('express');
var app=express();
var port=process.env.PORT || 3000;
var student=require('./student');
var stud=require('./students');
student(app); // pass your app variable, no need for the function name
app.listen(port);
console.log('listening on port'+port);
student.js:
module.exports = function (app) {
app.get('/getAllExcellenceStudent/', function(req, res) {
res.json.parse({name:'adi'});
})
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With