How to import routes in polka js similar to express.Route()How do JavaScript closures work?How do I check if an element is hidden in jQuery?How do I remove a property from a JavaScript object?How do I redirect to another webpage?How do I include a JavaScript file in another JavaScript file?How to check whether a string contains a substring in JavaScript?How do I pass command line arguments to a Node.js program?How to decide when to use Node.js?How do I remove a particular element from an array in JavaScript?How do I return the response from an asynchronous call?

no sense/need/point

Sci-fi/fantasy book - ships on steel runners skating across ice sheets

How can a hefty sand storm happen in a thin atmosphere like Martian?

Speed up this NIntegrate

Should I simplify my writing in a foreign country?

In linear regression why does regularisation penalise the parameter values as well?

How to properly store the current value of int variable into a token list?

Would a "Permanence" spell in 5e be overpowered?

Is throwing dice a stochastic or a deterministic process?

Is any special diet an effective treatment of autism?

Sheared off exhasut pipe: How to fix without a welder?

What happens if I accidentally leave an app running and click "Install Now" in Software Updater?

All of my Firefox add-ons been disabled suddenly, how can I re-enable them?

Simple Derivative Proof?

Which "exotic salt" can lower water's freezing point by –70 °C?

What Kind of Wooden Beam is this

Gerrymandering Puzzle - Rig the Election

What is a common way to tell if an academic is "above average," or outstanding in their field? Is their h-index (Hirsh index) one of them?

Is the book wrong about the Nyquist Sampling Criterion?

Dangerous workplace travelling

Where are the "shires" in the UK?

In "Avengers: Endgame", what does this name refer to?

Why did WWI include Japan?

My first C++ game (snake console game)



How to import routes in polka js similar to express.Route()


How do JavaScript closures work?How do I check if an element is hidden in jQuery?How do I remove a property from a JavaScript object?How do I redirect to another webpage?How do I include a JavaScript file in another JavaScript file?How to check whether a string contains a substring in JavaScript?How do I pass command line arguments to a Node.js program?How to decide when to use Node.js?How do I remove a particular element from an array in JavaScript?How do I return the response from an asynchronous call?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















I am trying to import route logic from another file. In express js this is achievable via express.Route(), when i tried polka.Route() an error pops up saying Route doesn't exist in polka.



Express Implementation



server.js



const express = require('express');
const users = require('./routes/api/users');
const app = express();
app.use('/users', users);


user.js



const express = require('express'); 
const router = express.Router();
router.get('/test', (req, res) => res.json( msg: 'works' ));
module.exports = router;


When /users/test is hit the output is msg:'works'. This works for the express implementation. For the polka implementation i changed the word express to polka installing it. The issue arises on the line polka.Router() of user.js. How do i enable this functionality of importing route logic from another file in polka.










share|improve this question




























    1















    I am trying to import route logic from another file. In express js this is achievable via express.Route(), when i tried polka.Route() an error pops up saying Route doesn't exist in polka.



    Express Implementation



    server.js



    const express = require('express');
    const users = require('./routes/api/users');
    const app = express();
    app.use('/users', users);


    user.js



    const express = require('express'); 
    const router = express.Router();
    router.get('/test', (req, res) => res.json( msg: 'works' ));
    module.exports = router;


    When /users/test is hit the output is msg:'works'. This works for the express implementation. For the polka implementation i changed the word express to polka installing it. The issue arises on the line polka.Router() of user.js. How do i enable this functionality of importing route logic from another file in polka.










    share|improve this question
























      1












      1








      1








      I am trying to import route logic from another file. In express js this is achievable via express.Route(), when i tried polka.Route() an error pops up saying Route doesn't exist in polka.



      Express Implementation



      server.js



      const express = require('express');
      const users = require('./routes/api/users');
      const app = express();
      app.use('/users', users);


      user.js



      const express = require('express'); 
      const router = express.Router();
      router.get('/test', (req, res) => res.json( msg: 'works' ));
      module.exports = router;


      When /users/test is hit the output is msg:'works'. This works for the express implementation. For the polka implementation i changed the word express to polka installing it. The issue arises on the line polka.Router() of user.js. How do i enable this functionality of importing route logic from another file in polka.










      share|improve this question














      I am trying to import route logic from another file. In express js this is achievable via express.Route(), when i tried polka.Route() an error pops up saying Route doesn't exist in polka.



      Express Implementation



      server.js



      const express = require('express');
      const users = require('./routes/api/users');
      const app = express();
      app.use('/users', users);


      user.js



      const express = require('express'); 
      const router = express.Router();
      router.get('/test', (req, res) => res.json( msg: 'works' ));
      module.exports = router;


      When /users/test is hit the output is msg:'works'. This works for the express implementation. For the polka implementation i changed the word express to polka installing it. The issue arises on the line polka.Router() of user.js. How do i enable this functionality of importing route logic from another file in polka.







      javascript node.js express routing






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 23 at 3:15









      MuljayanMuljayan

      443212




      443212






















          1 Answer
          1






          active

          oldest

          votes


















          1














          The polka micro web server does not implement a difference between routers and the app. In your users.js file simply setup your routes as you would in your server.js file and then module.export. See Below:



          Polka Implementation



          server.js



          const polka = require('polka');
          const users = require('./routes/api/users');
          const app = polka();
          app.use('/users', users);


          user.js



          const polka = require('polka'); 
          const router = polka();
          router.get('/test', (req, res) => res.end(JSON.stringify( msg: 'works' )));
          module.exports = router;


          Hope this help!



          Also, here is a good link to see other differences between Express.js and Polka.js: https://github.com/lukeed/polka#comparisons






          share|improve this answer

























          • Hi thank you for your answer it works. How ever it says res.json is not part of polka . How do i send json from polka

            – Muljayan
            Apr 2 at 3:42











          • My apologies. I updated the answer return JSON properly in using Polka. You have use res.end() and pass a String.

            – codedawi
            Apr 2 at 4:40











          • Also, polka.js providers a nice extension package @polka/send-type for responses of various different types. See: github.com/lukeed/polka/tree/master/packages/send-type

            – codedawi
            Apr 2 at 4:42











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55310267%2fhow-to-import-routes-in-polka-js-similar-to-express-route%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          The polka micro web server does not implement a difference between routers and the app. In your users.js file simply setup your routes as you would in your server.js file and then module.export. See Below:



          Polka Implementation



          server.js



          const polka = require('polka');
          const users = require('./routes/api/users');
          const app = polka();
          app.use('/users', users);


          user.js



          const polka = require('polka'); 
          const router = polka();
          router.get('/test', (req, res) => res.end(JSON.stringify( msg: 'works' )));
          module.exports = router;


          Hope this help!



          Also, here is a good link to see other differences between Express.js and Polka.js: https://github.com/lukeed/polka#comparisons






          share|improve this answer

























          • Hi thank you for your answer it works. How ever it says res.json is not part of polka . How do i send json from polka

            – Muljayan
            Apr 2 at 3:42











          • My apologies. I updated the answer return JSON properly in using Polka. You have use res.end() and pass a String.

            – codedawi
            Apr 2 at 4:40











          • Also, polka.js providers a nice extension package @polka/send-type for responses of various different types. See: github.com/lukeed/polka/tree/master/packages/send-type

            – codedawi
            Apr 2 at 4:42















          1














          The polka micro web server does not implement a difference between routers and the app. In your users.js file simply setup your routes as you would in your server.js file and then module.export. See Below:



          Polka Implementation



          server.js



          const polka = require('polka');
          const users = require('./routes/api/users');
          const app = polka();
          app.use('/users', users);


          user.js



          const polka = require('polka'); 
          const router = polka();
          router.get('/test', (req, res) => res.end(JSON.stringify( msg: 'works' )));
          module.exports = router;


          Hope this help!



          Also, here is a good link to see other differences between Express.js and Polka.js: https://github.com/lukeed/polka#comparisons






          share|improve this answer

























          • Hi thank you for your answer it works. How ever it says res.json is not part of polka . How do i send json from polka

            – Muljayan
            Apr 2 at 3:42











          • My apologies. I updated the answer return JSON properly in using Polka. You have use res.end() and pass a String.

            – codedawi
            Apr 2 at 4:40











          • Also, polka.js providers a nice extension package @polka/send-type for responses of various different types. See: github.com/lukeed/polka/tree/master/packages/send-type

            – codedawi
            Apr 2 at 4:42













          1












          1








          1







          The polka micro web server does not implement a difference between routers and the app. In your users.js file simply setup your routes as you would in your server.js file and then module.export. See Below:



          Polka Implementation



          server.js



          const polka = require('polka');
          const users = require('./routes/api/users');
          const app = polka();
          app.use('/users', users);


          user.js



          const polka = require('polka'); 
          const router = polka();
          router.get('/test', (req, res) => res.end(JSON.stringify( msg: 'works' )));
          module.exports = router;


          Hope this help!



          Also, here is a good link to see other differences between Express.js and Polka.js: https://github.com/lukeed/polka#comparisons






          share|improve this answer















          The polka micro web server does not implement a difference between routers and the app. In your users.js file simply setup your routes as you would in your server.js file and then module.export. See Below:



          Polka Implementation



          server.js



          const polka = require('polka');
          const users = require('./routes/api/users');
          const app = polka();
          app.use('/users', users);


          user.js



          const polka = require('polka'); 
          const router = polka();
          router.get('/test', (req, res) => res.end(JSON.stringify( msg: 'works' )));
          module.exports = router;


          Hope this help!



          Also, here is a good link to see other differences between Express.js and Polka.js: https://github.com/lukeed/polka#comparisons







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Apr 2 at 4:35

























          answered Mar 23 at 4:41









          codedawicodedawi

          1246




          1246












          • Hi thank you for your answer it works. How ever it says res.json is not part of polka . How do i send json from polka

            – Muljayan
            Apr 2 at 3:42











          • My apologies. I updated the answer return JSON properly in using Polka. You have use res.end() and pass a String.

            – codedawi
            Apr 2 at 4:40











          • Also, polka.js providers a nice extension package @polka/send-type for responses of various different types. See: github.com/lukeed/polka/tree/master/packages/send-type

            – codedawi
            Apr 2 at 4:42

















          • Hi thank you for your answer it works. How ever it says res.json is not part of polka . How do i send json from polka

            – Muljayan
            Apr 2 at 3:42











          • My apologies. I updated the answer return JSON properly in using Polka. You have use res.end() and pass a String.

            – codedawi
            Apr 2 at 4:40











          • Also, polka.js providers a nice extension package @polka/send-type for responses of various different types. See: github.com/lukeed/polka/tree/master/packages/send-type

            – codedawi
            Apr 2 at 4:42
















          Hi thank you for your answer it works. How ever it says res.json is not part of polka . How do i send json from polka

          – Muljayan
          Apr 2 at 3:42





          Hi thank you for your answer it works. How ever it says res.json is not part of polka . How do i send json from polka

          – Muljayan
          Apr 2 at 3:42













          My apologies. I updated the answer return JSON properly in using Polka. You have use res.end() and pass a String.

          – codedawi
          Apr 2 at 4:40





          My apologies. I updated the answer return JSON properly in using Polka. You have use res.end() and pass a String.

          – codedawi
          Apr 2 at 4:40













          Also, polka.js providers a nice extension package @polka/send-type for responses of various different types. See: github.com/lukeed/polka/tree/master/packages/send-type

          – codedawi
          Apr 2 at 4:42





          Also, polka.js providers a nice extension package @polka/send-type for responses of various different types. See: github.com/lukeed/polka/tree/master/packages/send-type

          – codedawi
          Apr 2 at 4:42



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55310267%2fhow-to-import-routes-in-polka-js-similar-to-express-route%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현