Deno is asynchronous JavaScript/TypeScript runtime. If you are not sure how and what’s of Deno, here is the links
- How to install Deno on Windows - Deno tutorial for beginners
- How to install Deno on Ubuntu Linux - Deno tutorial for beginners: how to install Deno on Windows
- Deno : next generation Node - About Deno TypeScript Runtime
Make a Deno server
With a single file and Oak dependency can create deno server app.
- Create project folder
- create a main.ts file
import { Application } from "https://deno.land/x/oak/mod.ts"; const app = new Application(); app.use((ctx) => { ctx.response.body = "Hello World!"; }); app.listen({ port: 8000 }); console.log('Serveris running on port 8000')
In the first line we import the Application from the Oak module, which is used to create our basic site.
Using the use method we add middleware and running port for server using listen method of the Application object (app).
deno run maint.ts
While running the file, you may encounter Permission Denied: network access error. One of the feature of Deno is the way it handling the different permissions. You need to allow program whatever need to do, writing, reading, accessing network etc. Let’s run it again with necessary permissions
deno run --allow-net main.ts
Now jump into the browser access your route http://127.0.0.1/.
Here our hello world route is a default route. What ever you type in route will get the same page. (http://127.0.0.1/index or http://127.0.0.1/about )
To stop the running server use Ctrl+C