• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Angular with Mongodb

 
Ranch Hand
Posts: 220
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am making a simple crud operation  web app with angular and mongodb it is giving error while connecting,

  • GET http://localhost/items net::ERR_CONNECTION_REFUSED zone.js:2224
    ERROR                                                                    core.es5.js:1084
    Response {_body: ProgressEvent, status: 0, ok: false, statusText: "", headers: Headers…}


  • server.js

    items.js

    index.js

    can someone pointout my mistake ?thanks in advance
     
    priyanshi bhardwaj
    Ranch Hand
    Posts: 220
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    priyanshi bhardwaj wrote:

    server.js


    I have one more query what is the use of above stated line in my server.js actually, I have been following a tutorial for writing this code so i didn't understand the meaning of the above line.
     
    Marshal
    Posts: 3149
    466
    Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    priyanshi bhardwaj wrote:
    I have one more query what is the use of above stated line in my server.js actually, I have been following a tutorial for writing this code so i didn't understand the meaning of the above line.


    Can you share a URL to the tutorial?
     
    Ron McLeod
    Marshal
    Posts: 3149
    466
    Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    priyanshi bhardwaj wrote:I am making a simple crud operation  web app with angular and mongodb it is giving error while connecting,


  • GET http://localhost/items net::ERR_CONNECTION_REFUSED zone.js:2224
    ERROR                                                                    core.es5.js:1084
    Response {_body: ProgressEvent, status: 0, ok: false, statusText: "", headers: Headers…}

  • You should first determine if the problem is with client side (Angular), or the server side (express.Router).  Trying using a tool like Postman to call the API methods and see if express return what you are expecting.

    The error message seems to indicate that client-side is unable to connect to express - either the IP address and/or port number that the client-side is using is incorrect, or express's listener didn't get started.
     
    priyanshi bhardwaj
    Ranch Hand
    Posts: 220
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I check it using postman serverside is creating problem all the above three  files are not getting load on server ? can you  please tell me a fix to it.
     
    priyanshi bhardwaj
    Ranch Hand
    Posts: 220
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    This the error which I am getting
  • GET http://localhost:4200/api/item 404 (Not Found)

  • kindly suggest me any fix for this
     
    Ron McLeod
    Marshal
    Posts: 3149
    466
    Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I've never used Express, but the path in the GET route looks strange to me: router.get('./item',function(req,res,next){...}.

    Should the leading dot character be there?  What purpose do it serve?

    According to the API Reference, the path can be:
       - A string representing a path.
       - A path pattern.
       - A regular expression pattern to match paths.
       - An array of combinations of any of the above.

    There are Path Examples in the document.

    Try removing the dot and see if there is any change.
     
    Ranch Hand
    Posts: 97
    AngularJS Chrome Linux
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi Priyanshi,

    I think problem with server side end point binding.



    It should use relative path using "/" I changed the URL in local and it works for me.



    Now your end points will be http://localhost:3000/api/item
     
    priyanshi bhardwaj
    Ranch Hand
    Posts: 220
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Good Afternoon everyone , I have tried your suggestion now I am getting an another error can you please have a look at this also
  • ReferenceError: db is not defined
    at C:\qwerty\routes.js:21:3
    at Layer.handle [as handle_request] (C:\qwerty\node_modules\express\lib\router\layer.js:95:5)
    at next (C:\qwerty\node_modules\express\lib\router\route.js:137:13)
    at Route.dispatch (C:\qwerty\node_modules\express\lib\router\route.js:112:3)
    at Layer.handle [as handle_request] (C:\qwerty\node_modules\express\lib\router\layer.js:95:5)
    at C:\qwerty\node_modules\express\lib\router\index.js:281:22
    at Function.process_params (C:\qwerty\node_modules\express\lib\router\index.js:335:12)
    at next (C:\qwerty\node_modules\express\lib\router\index.js:275:10)
    at SendStream.error (C:\qwerty\node_modules\serve-static\index.js:121:7)
    at emitOne (events.js:96:13)


  • AND the url for the tutorial iscrud app
     
    Dinesh Kumar Ramakrishnan
    Ranch Hand
    Posts: 97
    AngularJS Chrome Linux
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    You are trying to access the variable "db" which is not exists or visible in routes.js file. can you upload files in Github if possiable.
     
    priyanshi bhardwaj
    Ranch Hand
    Posts: 220
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    i have made some changes
    app.js

    routes.js

    database is making problem
     
    priyanshi bhardwaj
    Ranch Hand
    Posts: 220
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    this is the error and i am unable to retrieve database also
  • Uncaught SyntaxError: Unexpected token <  typescript.js:1
  •  
    Dinesh Kumar Ramakrishnan
    Ranch Hand
    Posts: 97
    AngularJS Chrome Linux
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    priyanshi bhardwaj wrote:this is the error and i am unable to retrieve database also

  • Uncaught SyntaxError: Unexpected token <  typescript.js:1


  • Make sure you are running mongodb in port number 27017 and database & collection named "items" is available in your db.

    Are you getting this error in node.js or in angular.js typescript conversion?
     
    priyanshi bhardwaj
    Ranch Hand
    Posts: 220
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I fixed the above error thanks but now i am getting another error
  • Cannot find module './lib/mongodb'
       at Function.Module._resolveFilename (module.js:469:15)

  • this error is for app.js. Can you help me with this but still i am unable to retrieve database i have checked all the things which you have mentioned above they exists in the database.
     
    priyanshi bhardwaj
    Ranch Hand
    Posts: 220
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    my another question is am i doing anything wrong in the codeing part actually i am new to this topic so i don't know much regarding this.
     
    Dinesh Kumar Ramakrishnan
    Ranch Hand
    Posts: 97
    AngularJS Chrome Linux
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    priyanshi bhardwaj wrote:I fixed the above error thanks but now i am getting another error

  • Cannot find module './lib/mongodb'
       at Function.Module._resolveFilename (module.js:469:15)

  • this error is for app.js. Can you help me with this but still i am unable to retrieve database i have checked all the things which you have mentioned above they exists in the database.



    You need install mongodb npm package to resolve this error. (npm install mongodb)

    Start with simple example.Try to create node end point with mongodb collection retrieval first, Later implement add/delete etc. Use mongoose to connect mongodb and fellow the below tutorial to connect node with monogodb

    https://developer.mozilla.org/en-US/docs/Learn/Server-side/Express_Nodejs
    http://mongoosejs.com/docs/
    https://scotch.io/tutorials/using-mongoosejs-in-node-js-and-mongodb-applications

    Never give up!  
     
    priyanshi bhardwaj
    Ranch Hand
    Posts: 220
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks for your suggestion i'll be back soon after completing this and with my more errors.
     
    With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
      Bookmark Topic Watch Topic
    • New Topic