Questions tagged [deno]
A secure runtime for JavaScript and TypeScript.
1,008
questions
106
votes
4
answers
42k
views
How to use npm module in DENO?
Deno is super cool. I saw it in the morning and want to migrate to deno now. I was trying to move my existing nodejs script to deno. Can any one help me on how to use npm modules in deno. I need ...
63
votes
3
answers
15k
views
deno vs ts-node : what's the difference
I'm working on a relative large typescript project, I'm using ts-node to run node testing and examples. As far as I understand, ts-node will compile ts files to js files and execute.
Recently I heard ...
39
votes
2
answers
12k
views
Node.js' __dirname & __filename equivalent in Deno
How can I get the directory & file name of the current module?. In Node.js I would use: __dirname & __filename for that
36
votes
5
answers
13k
views
How can one check if a file or directory exists using Deno?
The Deno TypeScript runtime has built-in functions, but none of them address checking the existence of a file or directory. How can one check if a file or directory exists?
36
votes
2
answers
14k
views
How can I avoid the "an import path cannot end with .ts extension" error in VSCode?
I'm using Visual Studio Code to write Deno programs.
The import statement in Deno contains the .ts extension, e.g.
import { Application } from "https://deno.land/x/oak/mod.ts";
which is ...
31
votes
3
answers
14k
views
How do I read a local file in Deno?
I'm writing a word count program written in TypeScript that I'm trying to run in Deno. I'm invoking it with no arguments, just deno ./word_count.ts, so it should have the default read-only filesystem ...
30
votes
5
answers
9k
views
How to debug Deno in VSCode
How do we configure .vscode/launch.json to debug Deno projects?
The IntelliSense the VSCode provides when I was in configurations didn't offer an option for Deno. Or is there an extension for this?
26
votes
2
answers
7k
views
Where can I see deno downloaded packages?
I am new to deno and currently exploring for a minimum viable project in deno. I want to like npm which downloads the npm packages inside the folder node_modules, similarly I want to see the deno ...
22
votes
1
answer
4k
views
How to exit in Deno? (analog of process.exit)
How to exit in Deno passing a status code?
In Node.js you could use process.exit(), what is its Deno's counterpart ?
21
votes
3
answers
6k
views
deno import JSON file as module
I have a simple file that imports a json:
main.ts
import json from './file.json'
However, deno throws the following error when importing a json file:
$ deno run main.ts
Compile file:///home/path/...
21
votes
9
answers
10k
views
Getting values from Deno stdin
How can we get values from standard input in Deno?
I don't know how to use Deno.stdin.
An example would be appreciated.
21
votes
5
answers
9k
views
How do I run an arbitrary shell command from Deno?
I want to run any arbitrary bash command from Deno, like I would with a child_process in Node. Is that possible in Deno?
20
votes
4
answers
6k
views
How to use deno in production
I tried Deno (https://deno.land/) in local pc and some of its examples and we have to run the server before executing the APIs in the local environment.
I need to host it in the server so that I can ...
18
votes
3
answers
7k
views
How to pass command line arguments to Deno?
I have a Deno app, that I wish to pass some command line args to. I searched the manual, but found nothing.
I tried to use the same commands used in Node.js, assuming they might be sharing some for ...
18
votes
4
answers
11k
views
How to delete runtime import cache in deno?
In node.js we can use
delete require.cache[require.resolve(somePath)];
to delete the require cache in runtime.
Is there a similar way to delete runtime import cache in deno?
17
votes
3
answers
8k
views
How to pull typings in Deno
I am checking out Deno and have found one of the starter examples very elegant:
import { serve } from "https://deno.land/x/[email protected]/http/server.ts";
const s = serve("0.0.0.0:8000");
void async ...
15
votes
8
answers
9k
views
How to Install Deno on Ubuntu
The command I run is:
curl -fsSL https://deno.land/x/install/install.sh | sh
The output is:
######################################################################## 100.0%
Archive: /root/.deno/bin/...
15
votes
1
answer
2k
views
How to run a Python Script from Deno?
I have a python script with the following code:
print("Hello Deno")
I want to run this python script (test.py) from test.ts using Deno. This is the code in test.ts so far:
const cmd = Deno.run({cmd:...
14
votes
5
answers
4k
views
Deno: How to substitute npm scripts (package.json)
Since it is not necessary to have package.json file with deno, how can I as a developer have a similar experience just as we have with npm scripts in package.json?
14
votes
4
answers
5k
views
Is there any way to convert a Node project to Deno?
I want to convert a Node.js project to Deno. Is there any guide available?
My current project has lots of NPM files and it's already in TypeScript.
Any tips?
14
votes
1
answer
5k
views
What's Deno equivalent of Node.js Buffer.from(string)
How can I convert a string to a buffer?
I tried: Uint8Array.from('hello world') but it isn't working
14
votes
7
answers
6k
views
Creating a Deno https server
I am looking for an example of creating a https server in Deno. I have seen examples of Deno http server but not https.
I have tried searching in google but found no results
14
votes
1
answer
781
views
Hardcoding large amounts of data without inducing memory spike
So I am exploring the concept of storing WebAssembly inside the JavaScript file so it can all be bundled up in one shippable file. I did manage to make a working example of this where it stores the ...
13
votes
2
answers
6k
views
How can I write files in Deno?
I was trying to write to a file using Deno.writeFile
await Deno.writeFile('./file.txt', 'some content')
But got the following cryptic error:
error: Uncaught TypeError: arr.subarray is not a ...
12
votes
2
answers
3k
views
How to import a module inside the Deno REPL?
Attempting to import a module in the Deno REPL results in the following error:
Uncaught SyntaxError: Cannot use import statement outside a module
at evaluate (rt/40_repl.js:60:36)
at replLoop (...
12
votes
3
answers
3k
views
deno import lodash from deno.land/x
I haven't been able to find the right syntax/URL to import Lodash in a Deno program.
I tried this:
import _ from 'https://deno.land/x/[email protected]/lodash.js';
That gives the error "Uncaught ...
11
votes
4
answers
4k
views
Deno allow all permissions
I often find myself typing at least two or three permission options when playing with Deno:
deno run --allow-net --allow-read --allow-env app.ts
There's a way to escape explicit permissions.
11
votes
1
answer
4k
views
How to make HTTP client requests with Deno
I'm playing around with Deno but I can't find the standard HTTP client.
I also googled "deno http client" which gives me https://deno.land/x/std/http/client/, but the link is broken. Something was ...
11
votes
3
answers
4k
views
How to console.log without a newline in Deno?
How do I print a new line to the terminal without a newline in Deno? In node.js I used to do:
process.stdout.write('hello, deno!')
Is this possible in Deno? Deno does not have the process module, and ...
11
votes
2
answers
3k
views
How to write a TCP chat server with Deno?
One of the demos that really convinced me of the power of Node was the simple TCP chat server that Ryan Dahl presented in this video: https://www.youtube.com/watch?v=jo_B4LTHi3I&t=28m23s
Here's ...
11
votes
1
answer
2k
views
How to get the output of a command in Deno?
For example, suppose I have the following code:
Deno.run({cmd: ['echo', 'hello']})
How do I collect the output of that command which is hello ?
10
votes
2
answers
2k
views
How can I download big files in Deno?
I'm trying to download a 10GB file, but only 4GB get saved to disk, and memory is growing a lot.
const res = await fetch('https://speed.hetzner.de/10GB.bin');
const file = await Deno.open('./10gb.bin'...
10
votes
2
answers
3k
views
What is the Deno equivalent of process.argv in Node.js?
When working with NodeJS, I can pass the arguments to a Node script like this:
$ node node-server.js arg1 arg2=arg2-val arg3
And can get the arguments like so:
// print process.argv
process.argv....
10
votes
5
answers
5k
views
Can i migrate my Node based project to Deno?
Hello I am a frontEnd developer.
First, I don't know much about the runtime environment.
Is it possible to convert my project into Deno with Node?
Even if I change all of my code,
I'm not sure if ...
10
votes
1
answer
2k
views
JWT authentication with Deno
How to create and validate JSON Web Token in Deno?
I am new to the Deno runtime, so it would be helpful to have a sample to get started with JWT in Deno.
10
votes
5
answers
5k
views
Deno Oak Disable Cors
I am trying to 'connect' my small React JS app with my Deno API backend on my local environment with fetch().
const apiUrl = `http://localhost:8000`;
try{
fetch(apiUrl)
.then((res) ...
10
votes
3
answers
4k
views
Usage of linters/linting tools within Deno
I am currently exploring Deno as proof-of-concept, and I am trying to find suitable way to setup linting within the project.
Here is part of the eslint configuration that I am thinking of setting up,...
10
votes
1
answer
1k
views
How to strongly type the Oak context state object in deno?
I want to strongly type the context.state object provided by oak in deno. I have already seen approaches how this could possibly work (e.g. Deno oak v10.5.1 context.cookies never being set), but have ...
10
votes
1
answer
2k
views
Does Deno have a window object
Deno claims to be browser-compatible. Does that mean it has a window / navigator object and what would that mean in terms of things like setting window.location?
9
votes
2
answers
2k
views
Deno permissions (--allow-net)
The one day old docs is not clear enough for me to know..
How to give global permission to all websites (for debugging stuff) in my deno project like..
deno run --allow-net=* deno.ts
or something ...
9
votes
6
answers
7k
views
Typescript Import Problem after updating Deno
I recently update deno from v1.3.0 to v1.4.0. Before updating, my code doesn't have any problem, but after that i have this error:
error: TS1205 [ERROR]: Re-exporting a type when the '--...
9
votes
2
answers
3k
views
How to format on save with the Deno VSCode extension?
I am using the vscode-deno extension and eventhough I turned on deno.enable, deno.lint and deno.unstable in my vscode settings, it does not format my code on save, which I suppose is the expected ...
9
votes
2
answers
13k
views
How to convert an arrayBuffer to a Uint8Array, in Deno?
I'm using the fetch api to download an image in Deno. On the Response object, i'm calling the arrayBuffer() method, to get the final data of the response:
const response = await fetch('https://www....
9
votes
5
answers
3k
views
GraphQL server with Deno
It works just once for the below code
import {
graphql,
GraphQLSchema,
GraphQLObjectType,
GraphQLString,
buildSchema,
} from "https://cdn.pika.dev/graphql/^15.0.0";
import { serve } from "...
9
votes
3
answers
5k
views
Deno on multi-core machines
In Node.js there is the cluster module to utilize all available cores on the machine which is pretty great, especially when used with the node module pm2. But I am pretty stoked about some features of ...
9
votes
4
answers
4k
views
Is there any alternative ajv(json-schema validator) for deno?
I'm looking for a ajv-like json schema validator for deno. Wondering is there any alternative?
9
votes
2
answers
635
views
CLI REPL with Deno
I would like to build a CLI application using Deno however I can't find a module that allows me to keep prompting the user for interaction similar to command line applications to the REPL module on ...
9
votes
1
answer
2k
views
How to limit Deno memory and cpu usage
How can I limit Deno RAM and CPU usage when running js/ts scripts?
deno run https://deno.land/[email protected]/examples/welcome.ts
9
votes
1
answer
9k
views
Cannot find name 'document'. Do you need to change your target library? Try changing the `lib` compiler option to include 'dom'.ts(2584)
I want to convert a html string to a html element in deno with typescript. I found this function for it:
function createElementFromHTML(htmlString: string) {
var div = document.createElement('div');
...
8
votes
3
answers
1k
views
Equivalent of `util.inspect` in Deno
Does Deno have a utility function that dumps a Object or primitive to a string like Node.js util.inspect?
For example in Node.js I create an json object and want to dump out its contents in Node:
&...