Overview of Deno JS - Installation and Building an API

ππππππ π‘ππππ
Search for a command to run...

ππππππ π‘ππππ
Simple and useful, thank you π€©
Note to Ubuntu users: he didn't say how works Deno installation. So, here is:
Add deno using CURL:
curl -fsSL https://deno.land/x/install/install.sh | sh
Use nano to edit the file and add these two lines:
sudo nano .bashrc
export DENO_INSTALL="/$HOME/.deno"
export PATH="$DENO_INSTALL/bin:$PATH"
Execute the file: source ~/.bashrc
That's it, run: deno
I'm a Graduate student at UT Arlington. I always feel that taking care of both physically and mentally are essential to our success. So, I start my daily routine at Fitness Recreation Center (gym) and registering slots daily is a hassle and due to co...

You might have seen some people using completely different source labels. Well, today we will see how to change the Twitter source label First, we need to have a Twitter developer account, if you don't have. 1) Just navigate to Twitter Developer web...

We all know, Artificial Intelligence (AI) is one of the most transformative tech evolutions of our times. Well, if you still not aware of what AI is? It is the simulation of human intelligence in machines that are programmed to think like humans and ...

I'm a Indian and I recently moved to the USA to pursue my Master's degree at UT Arlington. So I need to carry some essential documents digitally like passport, health reports and other Government id's to be on the safer side and I don't want others t...

In Machine Learning classification problems, there are often too many factors on the basis of which the final classification is done. These factors are basically variables called features. The higher the number of features, the harder it gets to visu...

brew install deno
For Windows, execute this command (Hope chocolatey is already installed)
choco install deno
And these are End points
| GET - /todos | Used to read all the data |
| POST - /todos (form data) | Used to insert the data |
| PUT - /todos/:id | Used to update an existing data |
| DELETE - /todos/:id | Used to delete an record |
Well, we will start with index.js Normally, in NodeJs we use express for routings and we import it using require keyword but in DENO Js we import from oak (As you can see in below code)
import { Application } from "https://deno.land/x/oak/mod.ts";
import { PORT } from "./config.js";
import router from "./router.js";
const app = new Application();
app.use(router.routes());
app.use(router.allowedMethods());
console.log(`Server is running. Open http://localhost:${PORT}`);
await app.listen({ port: PORT });
Step 2:
Setup configuration file i.e PORT and FilePath required to store JSON data
export const PORT = 5000;
export const FilePath = "./data/todos.json";
Step 3:
Now create get.js, post.js, delete.js, put.js and place it in the controller. For clear code view, you can check my GitHub repository.
Step 4:
Now create a router.js file which handles all the routings that are required for the application
import { Router } from "https://deno.land/x/oak/mod.ts";
import getTodos from "./Controllers/todos/get.js";
import postTodo from "./Controllers/todos/post.js";
import deleteTodo from "./Controllers/todos/delete.js";
import putTodo from "./Controllers/todos/put.js";
const router = new Router();
router.get("/", ({ response }) => {
response.body = "Todo Application using Deno";
});
router
.get("/todos", getTodos)
.post("/todos", postTodo)
.delete("/todos/:id", deleteTodo)
.put("/todos/:id", putTodo);
export default router;
Step 5:
The main difference in Deno to NodeJs is the flags which need to be passed while executing the application for read, write permissions And this is one of the reason Deno make more secure.
deno run --allow-net=:5000 --allow-read=./data/todos.json --allow-write=./data/todos.json ./index.js
Deno loads the modules once from the URL and cache it in your system. To reload the modules again, you need to provide --reload flag before running the program.
deno run --reload --allow-net ./index.js
Step 6:
Now we can test our application in postman
Hope it's useful A β€οΈ would-be Awesome π