Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 call that API when we request, but i don't know how to do it.

I have the experience in hosting PHP,.NET in production mode i haven't used Nodejs yet so i don't know that process.

like image 754
Nanda Avatar asked May 29 '20 08:05

Nanda


People also ask

Can I use Deno in production?

Due to its single executable and easily accessible Docker Images, Deno is a breeze to package for production. Even when the docker images were not published, a simple Dockerfile based on debian:slim with installation script will run your code without a problem.

Can Nodejs be used in production?

Node. JS is ideal for fast, lightweight, real-time web applications such as audio/video streaming, browser games, chats, collaboration tools social media, time trackers, and much more. For this reason, many companies decide to use Node. js in production.

Are any companies using Deno?

Since Ryan Dahl first announced Deno, it has made significant progress. 1.0 was released in August 2020, and companies like Slack, Netlify, and GitHub have adopted Deno. In addition, The Deno Company has also released its own edge serverless function platform, Deno Deploy.

What is Deno good for?

Deno is a simple, modern and secure runtime for JavaScript, TypeScript, and WebAssembly that uses V8 and is built in Rust. Provides web platform functionality and adopts web platform standards. Secure by default. No file, network, or environment access, unless explicitly enabled.

Is Deno widely used in production applications?

However, due to its infancy, Deno is not yet widely used or recommended for critical production applications. . Deno is open-source software available under the MIT license. Contributions are encouraged via the Deno Project and should follow the Deno contribution guidelines. Congratulations on your practical introduction to using Deno.

How do I run a deno program?

The run command runs any Deno code. And if you’re stuck, run deno --help, or deno -h, to get help using denocommands. Deno also provides a way to run programs from a local file, a URL, or by integrating with other applications in the stdin by using "-" (without quotes).

Why is Deno asking me to submit an application?

We request everyone using Deno to submit your applications so the community can grow even further and understand how Deno is maturing.

How is Deno different from Node JS?

Deno runs JavaScript or TypeScript or WebAssembly applications on the underlying V8 engine, just like Node.js does. For application developers, there are several noticeable differences between Deno and Node.js. Unlike the modular binaries in Node.js, Deno is a single binary application.


Video Answer


2 Answers

You can use the cloud provider of your preference, AWS, DigitalOcean, Azure... and install deno and then you can use pm2 using interpreter flag to automatically restart if the server crashes and/or start the server on boot.

The easiest way is to create an ecosystem.config.js

module.exports = {
  apps: [
    {
      name: "app",
      script: "./deno.js",
      interpreter: "deno",
      interpreterArgs: "run --allow-net --allow-read",
    },
  ],
};

And use interpreterArgs to pass arguments that you need to pass to deno.

Now all you need to do is:

pm2 start

Now your server will be available on whatever port you setup your server. You can use Nginx as a reverse proxy if you want too.

You can also use any process manager of your preference

like image 101
Marcos Casagrande Avatar answered Oct 07 '22 02:10

Marcos Casagrande


You can just use:

pm2 start index.ts --interpreter="deno" --interpreter-args="run --allow-net" 
like image 23
Aral Roca Avatar answered Oct 07 '22 02:10

Aral Roca