I have this code:
var express = require("express");
var app = express();
var path = require("path");
app.use(express.static(__dirname + '/public'));
app.get('/',function(req,res){
res.sendFile(path.join(__dirname+'/views/index.html'));
res.set('Access-Control-Allow-Origin', '*');
}).listen(3000);
console.log("Running at Port 3000");
app.get('/test', function(req, res) {
res.json(200, {'test': 'it works!'})
})
I will have many services (for example, testone), and I do not want all of them to be in one file.
I read in another question on Stack Overflow that I might need other files: var express = require("./model/services.js");And in this file write all the services, but it throws app is not definedwhen Node starts up.
How can I separate the codes?
source
share