节点中的并行:我可以知道,在 Node.js 中,我的脚本是直接运行还是由另一个脚本加载?
我正在寻找一种方法来判断 deno 脚本是直接运行还是由另一个模块导入。这在 deno 中可能吗?如果是这样怎么办?
我用的是橡木/德诺。我有一个从提供的 ejs 文件提交的表单。如何访问表单主体?当我将其记录到控制台时,它会打印:{type: "form", value: URLSearchParamsImpl {} }
帖子处理程序如下所示:
router.post("/add", async (ctx: RouterContext) => {
const body = (await ctx.request.body())
console.log(body)
ctx.response.redirect("/");
});
Run Code Online (Sandbox Code Playgroud) 每次我使用 时deno fmt,它都会自动将我的单引号转换为双引号。
更具体地说,whenfmt应用于这样的语句:
console.log( 'Deno' );
Run Code Online (Sandbox Code Playgroud)
声明修改为:
console.log("Deno");
Run Code Online (Sandbox Code Playgroud)
预期的行为是默认继续使用单引号。
有fmt选项配置吗?
我知道如何在 Python 中做到这一点。
#!/usr/bin/python
import sys
import os
import hashlib
import hmac
import base64
secretKey = bytes("passw@rd", 'UTF-8')
message = bytes(f'hello world\nhello deno', 'UTF-8')
encryptedKey = base64.b64encode(hmac.new(secretKey, message, digestmod=hashlib.sha256).digest())
print(encryptedKey)
Run Code Online (Sandbox Code Playgroud)

但我不知道如何在 den 中做到这一点。我希望在 deno 中得到与上面的 python 代码相同的结果。
我正在开发一些 Deno 项目,希望能够将 TypeScript 编译为 JavaScript 以在浏览器中运行(因为尚不支持 TS)。当我使用 NodeJS 时,我tsc使用 npm 安装了编译器,但仅仅为了访问tsc. Deno 有内置编译器吗?
我正在运行 Ubuntu 服务器。
我尝试使用https://deno.land/x/mongo@v0.21.2框架连接MongoDB Atlas到我的 Deno 应用程序 。我尝试使用下面的代码来运行我的应用程序。但我收到一个错误 这里出了什么问题No such host is known. (os error 11001)
错误
error: Uncaught Error: No such host is known. (os error 11001)
at unwrapResponse (rt\10_dispatch_json.js:24:13)
at sendAsync (rt\10_dispatch_json.js:75:12)
at async Object.connect (rt\30_net.js:221:13)
at async MongoClient.connect (client.ts:41:14)
at async mongodb.ts:33:1
Run Code Online (Sandbox Code Playgroud)
Mongodb.ts 文件
import { MongoClient } from "https://deno.land/x/mongo@v0.21.0/mod.ts";
const client1 = new MongoClient();
await client1.connect("mongodb+srv://user1:MYPASSWORD@cluster0.hmdnu.mongodb.net/TestingDB?retryWrites=true&w=majority");
const db = client1.database("TestingDB");
export default db;
Run Code Online (Sandbox Code Playgroud)
我用这个命令来运行我的服务器
deno run --allow-net --allow-write --allow-read --allow-plugin --unstable server.ts
Run Code Online (Sandbox Code Playgroud) 我知道有一个问题有同样的错误,但那里的答案对我没有帮助:deno 捆绑失败。类型“ReadableStream<R>”上不存在属性“getIterator”
\n这是完整的错误:
\n\xe2\x9d\xaf deno run --allow-all server.ts\n检查文件:///Users/hagenek/repos/mock-backend/server.ts\n错误:TS2339 [错误]:属性\'getIterator\'类型 \'ReadableStream\' 上不存在。\nreturn res.read.getIterator();\n~~~~~~~~~~~~\nat https://deno.land/std@0.83.0/异步/pool.ts:45:23
\n这是我的 server.ts 代码:
\nimport { Application } from "./deps.ts";\nimport router from "./routes.ts"\nconst PORT = 4000;\nconst app = new Application();\n\napp.use(router.routes()); // Pass our router as a middleware\napp.use(router.allowedMethods()); // Allow HTTP methods on router\n\nawait app.listen({ port: PORT });\nconsole.log(`Server running on PORT: ${PORT}`)\nRun Code Online (Sandbox Code Playgroud)\n路线.ts:
\nimport { Router } from "https://deno.land/x/oak/mod.ts";\nimport {\n addQuote,\n getQuotes,\n getQuote,\n updateQuote,\n deleteQuote,\n} from "./controllers/controller.ts";\n\ninterface ReadableStream<R> {\n getIterator(): any\n}\n\nconst router …Run Code Online (Sandbox Code Playgroud) 如何将 deno 的节点兼容模式与明确类型化的模块一起使用?我尝试了这个,但似乎没有按预期工作。
/// <reference types='npm:@types/three' />
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用 Deno 递归读取文件Deno.readDir,但他们提供的示例仅执行给定的文件夹:
for await (const entry of Deno.readDir(Deno.cwd())) {
console.log(entry.name);
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能使这个递归?
deno ×10
typescript ×3
node.js ×2
deno-fmt ×1
dependencies ×1
file-io ×1
format ×1
hash ×1
javascript ×1
mongodb ×1
npm ×1
oak ×1