有没有类似github的中文网站
最满意答案
我的猜测是你试图直接从父文件夹而不是从子目录运行
js
脚本。例如:如果你在目录
foo
而你的server.js
在subdirbar
,
那么如果你运行node bar/server.js
,那么..
将指向foo的父节点,而不是bar的父节点,这就是找不到文件的原因。foo +---bar | +----- server.js +---- aPage.html
您可以尝试
cd
进入bar
并运行node server.js
。或者将脚本中的
../aPage.html
更改为__dirname/../aPage.html
。PS:您可以使用
path.resolve
获取绝对路径。My guess is that you are trying to directly run the
js
script from the parent folder instead of from the subdirectory.for example: if you are in directory
foo
and yourserver.js
is in subdirbar
,
then if you runnode bar/server.js
, then..
will point to the parent of foo, instead of parent of bar, that's why the file is not found.foo +---bar | +----- server.js +---- aPage.html
You may try to
cd
intobar
and runnode server.js
.or change the
../aPage.html
in the script to be__dirname/../aPage.html
.PS: you can use
path.resolve
to get the absolute path.
相关问答
更多-
我的猜测是你试图直接从父文件夹而不是从子目录运行js脚本。 例如:如果你在目录foo而你的server.js在subdir bar , 那么如果你运行node bar/server.js ,那么..将指向foo的父节点,而不是bar的父节点,这就是找不到文件的原因。 foo +---bar | +----- server.js +---- aPage.html 您可以尝试cd进入bar并运行node server.js 。 或者将脚本中的../aPage.html更改为__dirnam ...
-
当您安装node.js时,您在哪里存储文件,以便Web浏览器可以显示您的内容? 例如,Apache有一个www文件夹。 哪里都行。 node.js不提供静态内容,它运行JavaScript。 您可以告诉它在启动时运行哪个脚本。 您可以编写一些提供静态内容的JavaScript,但是保留它的位置取决于您编写的代码。 node.js会替换客户端javascript吗? 只有在任何服务器端编程取代客户端JavaScript时。 在服务器端使用JS的一个优点是您可以在客户端和服务器上重用库。 请参阅Mojito,了 ...
-
node.js位于客户端< - > Web服务器流中的位置?(Where does node.js sit in the client <--> web server flow?)[2023-03-25]
首先是通常流程的“图表”: Client | v Request | v ... -
// imports first const http = require('http'), url = require('url'), querystring = require('querystring'), fs = require('fs'), path = require('path'); const hostname = '127.0.0.1', port = 3000; // main function should only route requests co ...
-
我应该把我的Node.js web项目文件夹放在Ubuntu 14中?(Where should I put my Node.js web project folder in Ubuntu 14?)[2022-03-17]
位置对节点服务器无关紧要。 你可以从任何地方运行它。 我从我的用户主目录运行它。 您需要学习一些步骤。 (1)您可能希望使用nginx / apache,并将nginx / apache指向您的节点端口。 (2)你可能想使用永久命名的npm模块,永久运行。 Location does not matter for node server. You can run it from any where. I am running it from my user home directory. There are ... -
问题是上传表单中的操作地址是/ api / photo 但是,当您访 ...
-
node.js部署问题(node.js deployment questions)[2022-12-23]
因此,您可能无法在典型的“托管服务器”上使用Node.js。 这些服务器通常运行Apache并且仅支持一组有限的语言。 有几个提供Node.JS托管的提供商,包括创作者:Joyent。 否则,您需要控制实际的服务器,以便您可以运行node myapp.js命令。 有关可能的提供者列表,请参见此处 。 一旦获得运行node myapp.js的应用程序,它应该开始处理传入的Web请求,就像任何其他Web服务器一样。 现在,如果有人使用nginx,他们可能会将其用作负载平衡器或提供静态内容。 如果您不明白如何或为 ... -
使用Express 您的节点中的服务器是正确的,但它始终将响应作为test发送。 由于您需要提供项目的静态文件,因此您可以使用express。 server.js var express = require('express'); var app = express(); app.use(express.static('public')); app.listen(3000, function () { console.log('Example app listening on port 3000!'); ...
-
Node.js local-web-server:找不到模块ws(全局安装)(Node.js local-web-server: can't find module ws (installed globally))[2022-04-05]
您只需在cmd-prompt中键入ws ,而不是node ws 。 从npm( https://www.npmjs.com/package/local-web-server )上的文档: $ npm install -g local-web-server $ ws 当您编写node ws节点正在寻找运行名为ws的模块。 如果要使用全局安装的软件包,只需在cmd-prompt中使用软件包的名称即可。 Instead of node ws you just type wsin the cmd-prompt. ... -
正如加里所说,你绝对应该首先阅读文档,尤其是入门指南。 Stackoverflow不是为每个初学者提供自己的指南,这就是为什么有些人会对这些问题进行投票。 但要回答你的问题: http.createServer(app).listen(port, [hostname], [backlog], [callback]) 没有给回调函数的参数。 这就是req和res undefined 。 因此,您可以将代码更改为: app.listen(port, function(){ console.log("Ser ...