My code is not getting executed successfully

routes1>
todos1.js

const route1 = require(‘express’).Router()

let todos1=[
{task: “This is the first task”},
{task: “This is another task”}
]

route1.get(’/’,(req,res)=>{
res.render(‘todos1’,{todos1})
})

route1.post(’/’,(req,res)=>{

})

module.exports = route1


todos1.hbs

Document
<body>
    <form action="/todos1" method="POST">
        <input name="newtodo1">
        <input type="submit">

    </form>

    <ul>
        {{#each todos1 as |todo1|}}
            <li>{{todo1.task}}</li>
        {{/each}}}}
    </ul>

</body>
********************* serverX.js const express = require('express')

const todoRoute1 = require(’./routes1/todos1’)

const srv1=express()

srv1.set(‘view engine’, ‘hbs’)
srv1.set(‘views’,__dirname+"/views1")
srv1.use(express.json())

srv1.use(express.urlencoded({extended:true}))

srv1(’/todos1’,todoRoute1)

srv1.listen(3456)


error :-

/Users/deeptisharma/Desktop/Ajax1/express_serverside_rendering/node_modules/express/lib/router/index.js:160
req.next = next;
^

TypeError: Cannot create property ‘next’ on string ‘/todos1’
at Function.handle (/Users/deeptisharma/Desktop/Ajax1/express_serverside_rendering/node_modules/express/lib/router/index.js:160:12)
at Function.handle (/Users/deeptisharma/Desktop/Ajax1/express_serverside_rendering/node_modules/express/lib/application.js:174:10)
at app (/Users/deeptisharma/Desktop/Ajax1/express_serverside_rendering/node_modules/express/lib/express.js:39:9)
at Object. (/Users/deeptisharma/Desktop/Ajax1/express_serverside_rendering/serverX.js:21:1)
at Module._compile (internal/modules/cjs/loader.js:1138:30)
at Object.Module._extensions…js (internal/modules/cjs/loader.js:1158:10)
at Module.load (internal/modules/cjs/loader.js:986:32)
at Function.Module._load (internal/modules/cjs/loader.js:879:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47

@sharma.deepti182 the code above is correct, and there is no line req.next = next,
try deleting the node_modules folder, and install again using npm install and run the application again, to see if the error repeats. Also check if this is the updated code you are having problem with.

It’s still not working

@sharma.deepti182 upload the code on github and share the link with me, also share code on github or similar software, instead of typing it all in the text block (attach the error screenshot too)

@sharma.deepti182 in your serverX.js file, you have srv1('/todos1',todoRoute1) which should be this srv1.use('/todos1',todoRoute1). Try this and see if this is working

Its working now thanks