Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在谷歌云存储的后端使用javascript?_Javascript_Node.js_Google Cloud Storage_Serverside Javascript - Fatal编程技术网

在谷歌云存储的后端使用javascript?

在谷歌云存储的后端使用javascript?,javascript,node.js,google-cloud-storage,serverside-javascript,Javascript,Node.js,Google Cloud Storage,Serverside Javascript,我读到Javascript可以用于网站的后端,就像服务器端脚本一样。我已经看到谷歌云存储接受nodejs,但使用nodejs让我感到困惑,因为我不知道如何在文本编辑器(如括号)中使用它 我一直在尝试创建服务器,并使用控制台显示有人已连接: var http = require("http"); var fs = require("fs"); var lemon = 2; function send404Response(response) { response.writeHead(404, {

我读到Javascript可以用于网站的后端,就像服务器端脚本一样。我已经看到谷歌云存储接受nodejs,但使用nodejs让我感到困惑,因为我不知道如何在文本编辑器(如括号)中使用它

我一直在尝试创建服务器,并使用控制台显示有人已连接:

var http = require("http");
var fs = require("fs");
var lemon = 2;

function send404Response(response) {
response.writeHead(404, {"Content-Type": "text/plain"});
response.write("Error 404");
response.end;
}

function onRequest(request, response) {
if (request.method == 'GET' && request.url == '/'){
      response.writeHead(200, {"Content-Type": "text/html"});
    //sends back a readable stream
    fs.createReadStream("./index.html").pipe(response);
} else {
    send404Response(response);
}

}
http.createServer(onRequest).listen(8080);
console.log("Server is now running...");
“require”在定义之前已被使用。var http=require(“http”);是第一个错误,我不知道该做什么,也找不到任何帮助,除了我不应该做的网站需要

在回顾中,请回答以下问题:

  • 如何使用Javascript编写服务器端脚本和一些 教程会很有用

    • 如何在网站上使用nodejs,因为它是一个命令行
    • 代码有什么问题
  • 另外,在使用实时更新时,我应该使用哪个端口


如果问题有问题,请留下评论。我已尝试遵守规则。

请检查。您使用Node.js作为服务器,而不是客户端。我使用的括号与Node js不一样,因此“require”有问题,但对网站功能没有影响。