用于获取http的Javascript变量 [英] Javascript variables for Get http
问题描述
我正在学习JavaScript,并且想做与PHP $_GET[Var] = $foo;
类似的JavaScript我正在为项目编码基本的CDN类型服务器,
另外,我该如何提供要使用JavaScript下载的文件?计划是在NodeJS节点内运行此代码.抱歉,如果我不好解释,我会很糟糕.
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.
推荐答案
要从Node.js应用提供现有文件,请在express
和express.static
之间使用:
To serve existing files from your Node.js app, use express
with express.static
: http://expressjs.com/en/starter/static-files.html
以下示例使用ECMAScript 2015元素,并假定Node.js 4或5的静态文件存储在public
目录中:
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}`);
}
这篇关于用于获取http的Javascript变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!