In general, defining a route in Opine web framework can be done in the same way we do in Express.js framework by importing Route class from Opine package and create an instance from this class. However, all routes should be defined in a separated folder such as “routes” folder for example. Doing so, we could find all routes in one place.

 

// main.ts

import opine from "https://deno.land/x/opine@2.2.0/mod.ts"

const app = opine()

import indexRouter from './routes/index.ts'
app.use('/',indexRouter)

app.listen(3000);
console.log("Opine started on port 3000")

 

// routes/index.ts

import {Router} from "https://deno.land/x/opine@2.2.0/mod.ts"
const indexRouter = Router()

indexRouter.get('/', (req,res)=>{
    res.send('ទំព័រ​ដើម')
})

export default indexRouter