You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jun 14, 2024. It is now read-only.
throw new TypeError('Router.use() requires a middleware function but got a ' + gettype(fn))
^
TypeError: Router.use() requires a middleware function but got a string
at Function.use (D:\Web Development\Complete Web Development Boot camp\Node.JS Backend\Lecture 72\node_modules\express\lib\router\index.js:458:13)
at Function. (D:\Web Development\Complete Web Development Boot camp\Node.JS Backend\Lecture 72\node_modules\express\lib\application.js:220:21)
at Array.forEach ()
at Function.use (D:\Web Development\Complete Web Development Boot camp\Node.JS Backend\Lecture 72\node_modules\express\lib\application.js:217:7)
at Object. (D:\Web Development\Complete Web Development Boot camp\Node.JS Backend\Lecture 72\app.js:16:5)
at Module._compile (internal/modules/cjs/loader.js:1072:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
at Module.load (internal/modules/cjs/loader.js:937:32)
at Function.Module._load (internal/modules/cjs/loader.js:778:12)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
My code is
//Using the previous code with few changes.
const express = require('express'); //Imported the module I installed in last leture
const path = require ('path');
const app = express(); //Created my app
const port = 80; //The port on which i want to listen.
// Setting template engine as pug
app.set('view engine', 'pug')
//Set the views directory
app.use('views', path.join(__dirname, 'views'));
//Our pug demo end point
app.get("/demo", (req, res)=>{
res.status(200).render('demo', { title: 'Hey Harry', message: 'Hello there and thanks for telling me how to use pubG!' })
});
app.get("/", (req, res)=>{
res.send("This is home page of express app")
})
app.get("/about", (req, res)=>{
res.status(200).send("This is get request of about page of express app")
})
app.post("/about", (req, res)=>{
res.send("This is post request of about page of express app")
})
app.get("/this", (req, res)=>{
res.status(404).send("Page not found");
})
app.listen(port,() =>{
console.log(My express app is successfully started at port ${port});
})
I have tried the
const router = express.router();
module.exports = router;
But still it is not working.
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Hi!! This is the error I am getting
TypeError: Router.use() requires a middleware function but got a string
at Function.use (D:\Web Development\Complete Web Development Boot camp\Node.JS Backend\Lecture 72\node_modules\express\lib\router\index.js:458:13)
at Function. (D:\Web Development\Complete Web Development Boot camp\Node.JS Backend\Lecture 72\node_modules\express\lib\application.js:220:21)
at Array.forEach ()
at Function.use (D:\Web Development\Complete Web Development Boot camp\Node.JS Backend\Lecture 72\node_modules\express\lib\application.js:217:7)
at Object. (D:\Web Development\Complete Web Development Boot camp\Node.JS Backend\Lecture 72\app.js:16:5)
at Module._compile (internal/modules/cjs/loader.js:1072:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
at Module.load (internal/modules/cjs/loader.js:937:32)
at Function.Module._load (internal/modules/cjs/loader.js:778:12)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
My code is
//Using the previous code with few changes.
const express = require('express'); //Imported the module I installed in last leture
const path = require ('path');
const app = express(); //Created my app
const port = 80; //The port on which i want to listen.
//Change 1 : For serving static files
app.use('/static', express.static('static'));
// app.use("url", express.static("folder_name"));
// Setting template engine as pug
app.set('view engine', 'pug')
//Set the views directory
app.use('views', path.join(__dirname, 'views'));
//Our pug demo end point
app.get("/demo", (req, res)=>{
res.status(200).render('demo', { title: 'Hey Harry', message: 'Hello there and thanks for telling me how to use pubG!' })
});
app.get("/", (req, res)=>{
res.send("This is home page of express app")
})
app.get("/about", (req, res)=>{
res.status(200).send("This is get request of about page of express app")
})
app.post("/about", (req, res)=>{
res.send("This is post request of about page of express app")
})
app.get("/this", (req, res)=>{
res.status(404).send("Page not found");
})
app.listen(port,() =>{
console.log(
My express app is successfully started at port ${port}
);})
I have tried the
const router = express.router();
module.exports = router;
But still it is not working.
The text was updated successfully, but these errors were encountered: