Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

group is not a function #1

Open
fdorantesm opened this issue Jun 11, 2017 · 4 comments
Open

group is not a function #1

fdorantesm opened this issue Jun 11, 2017 · 4 comments

Comments

@fdorantesm
Copy link

Hi Dirk, thanks for this mod.

I tried to use it, but i couldn't do it because group function doesn't exists:

app.group("/api/v1", (router) =>{
^

TypeError: app.group is not a function
    at Object.<anonymous> (/www/nodejs/apiblog/config/routes.js:10:5)
    at Module._compile (module.js:410:26)
    at Object.Module._extensions..js (module.js:417:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Module.require (module.js:354:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/www/nodejs/apiblog/app.js:8:14)
    at Module._compile (module.js:410:26)
    at Object.Module._extensions..js (module.js:417:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Function.Module.runMain (module.js:442:10)
    at startup (node.js:136:18)
    at node.js:966:3

What i'm doing wrong?

var app = require('express')
// var router = express.Router()
require('express-group-routes');

var userController = require('../controllers/userController')
var mainController = require('../controllers/mainController')
var postController = require('../controllers/postController')

// router.get('/api',mainController.index)
app.group("/api/v1", (router) =>{
	router.get("/user/:id",userController.user)
	router.get("/users",userController.users)
	router.get("/posts",postController.posts)
	router.get("/posts/:id",postController.post)
})

module.exports = router
@Smahrt
Copy link

Smahrt commented Jun 21, 2017

I have this same issue. Have you found a solution yet?

@fdorantesm
Copy link
Author

Nope, but i used route function.

router.route('/api/v1')
    .post((req, res)=>{ })
    .get((req, res)=>{ })

;)

@domzgarcia
Copy link

domzgarcia commented Jan 8, 2019

Hi @fdorantesm, you should include express-group-routes before you invoke this express()
because its kind of prototyping inside the core.

https://github.com/domzgarcia/social-monitoring-v4/blob/master/core/bootstrap/RoutesManager.js#L10

@reisap
Copy link

reisap commented Mar 15, 2020

for handle this issue please provide like this.

require('express-group-routes'); //<-------need first implementation
import express from "express";// Init an Express App.

//.....line of code

app.group("/api/v1", (router) =>{
router.get("/user/:id",userController.user)
router.get("/users",userController.users)
router.get("/posts",postController.posts)
router.get("/posts/:id",postController.post)
});

//hope this help. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants