I am learning JavaScript and would like to do the JavaScript equivalent of PHP's $_GET[Var] = $foo;
I am coding a basic CDN type server for a project,
also, how can I serve a file for download with JavaScript? The plan is to run this code inside a NodeJS node. Sorry if I explained this badly, I am terrible at explaining things.
Asked
Active
Viewed 64 times
2
-
Possible duplicate of [How to get GET (query string) variables in Express.js on Node.js?](http://stackoverflow.com/questions/6912584/how-to-get-get-query-string-variables-in-express-js-on-node-js) – Venkat.R Jan 03 '16 at 01:22
1 Answers
0
To serve existing files from your Node.js app, use express
with express.static
: http://expressjs.com/en/starter/static-files.html
Example below uses ECMAScript 2015 elements and assumes Node.js 4 or 5 with static files stored in public
directory:
const http = require('http');
const express = require('express');
const app = express();
app.use(express.static('public'));
const server = http.createServer(app).listen(8080, serverCallback);
function serverCallback() {
const host = server.address().address;
const port = server.address().port;
console.log(`Server listening on ${host}:${port}`);
}

krl
- 5,087
- 4
- 36
- 53
-
with javascript is it possible to serve a file for download, if its name matches the get request in the url? – alex tix Jan 02 '16 at 18:03
-
-
1
-
-
It was not the answer to the question, that is just a simple web server. – alex tix Jan 04 '16 at 13:29