OK sorry if this a dumb question, I'm new to node. So I know I can do all this with express render and sendfile but is there a way so I can use both http and express. Basically using http.createServer to get GET calls with no query strings... var http = require('http'); var fs = require('fs'); var server = http.createServer(function(req,res){ if(req.url === '/home' || req.url === '/'){ res.writeHead(200, {'Content-Type': 'text/html'}); fs.createReadStream(__dirname + '/views/index.html').pipe(res); } }); server.listen(3000); Then after that use express to get GET calls WITH a query string... var express = require('express'); var app = express(); app.listen(3000); app.get('/', function(req, res){ if(req.query.somevariable){ send(stuff); } }); This is not working obviously, what would be the best way to do this, combining express and http? should i create one server for both?
Submitted August 02, 2018 at 07:33PM by Hellaimportantsnitch
No comments:
Post a Comment