Comments (4)
I agree with Wes.
I'll add this to give you some suggestion though.
import { Router as viewRouter } from 'express'
viewRouter().get('/', (req, res) => {
res.render('index')
})
export default viewRouter
Router
is a function.
I would suggest the following instead for viewRouter.js
export default app => {
app.get('/', (req, res) => {
res.render('index')
})
}
and in sicapp.js
,
import express from 'express'
import viewRouter from './routes/viewRouter.js'
// other code
...
const app = express()
....
viewRouter(app)
from express.
Thank you both, I appreciate the feedback :D
Wes, not a problem. I'm not sure there is any particular use in supporting bun anyways as they either have wrappers or have their own implementation of node libraries. I think what it was though is the file encoding got messed up and maybe lost it from there? My suspicion is a formatter in VsCode.
Joey, this is an excellent alternative to what I was trying to do and even cleaner at that. I will have to take a gander at this when I'm in front of my editor again. Much appreciated.
from express.
I am nearly positive even if you get this issue worked out you will just hit other issues. Express couples deeply to Node.js api's which are likely different enough to matter. Just don't want to provide an answer on the errors without pointing out you are likely in for a world of pain 🤣. Additionally I don't think it has been discussed yet, but we likely do not have any plans to support Bun, so YMMV on this effort even in the longer term.
That said, it looks to me like something else is up with your code as I am not sure how the runtime difference could cause a typeof check to fail. And since that is the case, I am going to close this since we do not do technical support in here. If you can prove this is a bug of some sort in express please re-open this, but otherwise I would ask on Reddit or StackOverflow.
from express.
One thing I made an oopsie here with is the module.exports= viewRouter
line which is commonJS .
Change it to default export viewRouter and I get the following error:
TypeError: argument handler must be a function
at /mnt/z/sic-web/src/node_modules/router/lib/route.js:211:15
at /mnt/z/sic-web/src/node_modules/express/lib/application.js:474:5
at /mnt/z/sic-web/src/sicapp.js:11:1
206 |
207 | for (var i = 0; i < callbacks.length; i++) {
208 | var fn = callbacks[i]
209 |
210 | if (typeof fn !== 'function') {
211 | throw new TypeError('argument handler must be a function')
^
TypeError: argument handler must be a function
at /mnt/z/sic-web/src/node_modules/router/lib/route.js:211:15
at /mnt/z/sic-web/src/node_modules/express/lib/application.js:474:5
at /mnt/z/sic-web/src/sicapp.js:11:1
^C
cain@cain-pc:/mnt/z/sic-web/src$ bun run dev
$ bun --hot sicapp.js
206 |
207 | for (var i = 0; i < callbacks.length; i++) {
208 | var fn = callbacks[i]
209 |
210 | if (typeof fn !== 'function') {
211 | throw new TypeError('argument handler must be a function')
^
TypeError: argument handler must be a function
at /mnt/z/sic-web/src/node_modules/router/lib/route.js:211:15
at /mnt/z/sic-web/src/node_modules/express/lib/application.js:474:5
at /mnt/z/sic-web/src/sicapp.js:12:1
206 |
207 | for (var i = 0; i < callbacks.length; i++) {
208 | var fn = callbacks[i]
209 |
210 | if (typeof fn !== 'function') {
211 | throw new TypeError('argument handler must be a function')
^
TypeError: argument handler must be a function
at /mnt/z/sic-web/src/node_modules/router/lib/route.js:211:15
at /mnt/z/sic-web/src/node_modules/express/lib/application.js:474:5
at /mnt/z/sic-web/src/sicapp.js:12:1
from express.
Related Issues (20)
- How to send a request at JSON format using http module to an ExpressJS server? HOT 1
- when NODE_ENV='production' getting error on request send HOT 2
- How to flush a response? HOT 2
- How do you guys set the `req.hostname`? HOT 1
- [deleted] HOT 3
- Request triager role for @SarthakParikh HOT 1
- Working On Vite+React. Have an Issue. HOT 1
- 4.19.0 breaks passing new URL() into res.redirect(...) HOT 7
- The npm latest version of express is 5.0.0-beta.2 !!! HOT 10
- Troubleshooting Node.js Express Server Routing Issue HOT 1
- mime.charsets in Response.js is undefined HOT 8
- WebAssembly Out of memory Error for any server HOT 2
- return res.redirect('back'); returns to '/' instead of the previous page HOT 2
- Need a clarification on router.param() usage. HOT 4
- [Question] Should Express.js v5.x drop support to older versions of Node? HOT 3
- .get() attempting to grab from home dir (Linux) HOT 2
- Request triager role for Ivaylo-Iv HOT 1
- Request triager role for etroynov HOT 2
- clean code for switch condition HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from express.