Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

305
Visualizações
How to import a Typescript or Javascript file from an external link?

I want to use some of the Deno standard libraries in Node.js to create an HTTP server.

I know that I can just download it but I want to stay updated with the latest library so I want to import them like this:

import { serve } from "https://deno.land/std/http/server.ts";

// Defining port to be used
const PORT = 8080
// Setting server to listen at port
const server = serve({ port: PORT });
console.log(`This Hello World server is up and running on http://localhost:${PORT}/`);

// Sending Hello World to any client that connects
for await (const req of server) {
    req.respond({ body: "Hello World!\n" });
}
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

It's theoretically possible to use a limited subset of the Deno std library in Node (modules which use nothing from the web APIs, nothing from the Deno API, and include no import statements with specifiers ending in .ts).

However, the module from your example at https://deno.land/std/http/server.ts does not meet this criteria and will create both compile-time errors in tsc (TypeScript) and runtime errors in Node.js.

about 4 years ago · Juan Pablo Isaza Relatório

0

Nevermind I just want to use ES6+ syntax to create a server so I use this:

import https from "https";
import http from "http";

export default class Server {
    readonly server: http.Server | https.Server;

    constructor(options?: http.ServerOptions | https.ServerOptions, httpsMode?: boolean) {
        this.server = (httpsMode ? https : http).createServer(options);
    }

    listen(port?: number, hostname?: string, backlog?: number) {
        let s = this.server;
        s.listen(port, hostname, backlog);
        return {
            [Symbol.asyncIterator]() {
                return {
                    async next() {
                        return {
                            done: false,
                            value: await new Promise<{request: http.IncomingMessage, response: http.ServerResponse}>(result => {
                                s.on('request', (request, response) => 
                                    result({request, response})
                                );
                            })
                        };
                    }
                }
            }
        }
    }

    close() {
        this.server.close();
    }
}

This module is available on NPM, package Newer.js after I publish 0.0.4

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda