Deno 使用 v8 来执行 javascript,但考虑到它直接运行 typescript 的事实,我想知道是否会因此而导致性能损失。
似乎它只是第一次编译代码。那么是否可以将编译作为部署步骤并避免与编译相关的启动开销?
node.js 和 Deno 之间的性能比较还有其他方面吗?
编写Deno脚本时,有时它们可以使用命令行执行deno run,但同时可能包含可以通过从另一个脚本导入来使用的库。
在 Deno 中执行此操作的正确方法是什么?
Python 中的等效内容是放在脚本的底部:
if __name__ == '__main__':
main(sys.argv[1:])
Run Code Online (Sandbox Code Playgroud)
这应该如何完成Deno?
在使用 Deno 时,我经常发现自己至少输入了两到三个权限选项:
deno run --allow-net --allow-read --allow-env app.ts
Run Code Online (Sandbox Code Playgroud)
有一种方法可以逃避显式权限。
正在阅读deno的主页新的 JS 运行时
我看到了以下代码:
import { serve } from "https://deno.land/std@0.50.0/http/server.ts";
const s = serve({ port: 8000 });
console.log("http://localhost:8000/");
for await (const req of s) {
req.respond({ body: "Hello World\n" });
}
Run Code Online (Sandbox Code Playgroud)
我从未见过以下语法(for await):
for await (const req of s) {
req.respond({ body: "Hello World\n" });
}
Run Code Online (Sandbox Code Playgroud)
这种语法是什么?
它是特定于 deno 还是在这个 tc39 提案中找到的顶级等待?
编辑:为什么它被使用以外的的async功能?
我为 Deno POC 编写了几个 api。
这是路线代码:
const router = new Router()
router.get('/posts', getPosts)
.get('/posts/:id', getPostsById)
Run Code Online (Sandbox Code Playgroud)
对于第二条路线,我可以使用关键字:params 在控制器中获取路径参数:getPostsById。这是控制器代码:
export const getPostsById = (
{ params, response }: { params:any, response: any }) => {
console.log(params, '||| params')}
Run Code Online (Sandbox Code Playgroud)
如何以类似的方式获取查询参数(例如:/posts/2222?userId=3)
我使用 Oak 进行路由。我尝试了 Oak 代码库中的各种关键字:查询、搜索等,但没有成功。
我也尝试了 Oak 文档中的 getQuery,但我完全无法导入它。
假设我有 2 个脚本,father.ts 和 child.ts,我如何从father.ts 生成child.ts 并定期从father.ts 向child.ts 发送消息?
我第一次使用 deno,这The system cannot find the path specified. (os error 3)是我遇到的错误。我的代码如下:-
import { Application } from 'https://deno.land/x/oak/mod.ts'
const app = new Application();
const port = 3000;
app.use((ctx) => {
ctx.response.body = "Hello World"
})
app.listen({ port })
console.log(`localhost:${port}`)
Run Code Online (Sandbox Code Playgroud)
我正在使用deno run --allow-net .\server.jspowershell 来启动 deno。任何帮助,将不胜感激。
编辑:如果我尝试做一个简单的 console.log 并运行文件,deno run server.js它运行良好,这意味着 deno 环境设置正确。一旦我在顶部添加 import 语句,错误就会开始发生。
我见过:How can I return html or json with deno? 但我需要橡树的答案 - 下面发布。
我有这样的错误:
error: Cannot resolve module "<path>/src/routes" from "<path>/src/index.ts"
Imported from "file:///F:/Development/k8demo/api-deno/src/index.ts:2"
Run Code Online (Sandbox Code Playgroud) 我最近将 deno 从 v1.3.0 更新到 v1.4.0。在更新之前,我的代码没有任何问题,但之后我有这个错误:
error: TS1205 [ERROR]: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
LevelName,
~~~~~~~~~
at https://deno.land/x/branch@0.0.2/deps.ts:8:3
TS1205 [ERROR]: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
export { LogConfig, setup, prefix } from "./branch.ts";
~~~~~~~~~
at https://deno.land/x/branch@0.0.2/mod.ts:3:10
TS1371 [ERROR]: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
import { WatcherConfig } from "./watcher.ts"; …Run Code Online (Sandbox Code Playgroud)