I've been following the instructions for how to set up a Node.js application using Loopback as described onToptal and Developing APIs with Node.js and LoopBack.io. Following these steps, I get a UrlNotFoundError when I try to access the REST API for the application.
Steps to reproduce:
- Installed the Strongloop command line:
$ npm install -g strongloop
- Run the Loopback's application generator:
$ slc loopback
. - Run the project:
$ node .
The terminal displays the followingWeb server listening at: http://0.0.0.0:3000 Browse your REST API at http://0.0.0.0:3000/explorer
- Browse the REST API.
- Try to POST to /Users with the provided model.
This results in the following response:
{
"error": {
"statusCode": 404,
"name": "Error",
"message": "Cannot POST /api/Users",
"status": 404,
"stack": "Error: Cannot POST /api/Users\n at raiseUrlNotFoundError (/Repos/loopback-test/node_modules/loopback/server/middleware/url-not-found.js:20:17)\n at Layer.handle [as handle_request] (/Repos/loopback-test/node_modules/loopback/node_modules/express/lib/router/layer.js:95:5)\n at trim_prefix (/Repos/loopback-test/node_modules/loopback/node_modules/express/lib/router/index.js:312:13)\n at /Repos/loopback-test/node_modules/loopback/node_modules/express/lib/router/index.js:280:7\n at Function.process_params (/Repos/loopback-test/node_modules/loopback/node_modules/express/lib/router/index.js:330:12)\n at next (/Repos/loopback-test/node_modules/loopback/node_modules/express/lib/router/index.js:271:10)\n at /loopback-test/node_modules/loopback/node_modules/async/dist/async.js:486:20\n at replenish (/Repos/loopback-test/node_modules/loopback/node_modules/async/dist/async.js:879:29)\n at /loopback-test/node_modules/loopback/node_modules/async/dist/async.js:888:13\n at eachLimit$1 (/Repos/loopback-test/node_modules/loopback/node_modules/async/dist/async.js:3136:26)\n at Object.<anonymous> (/Repos/loopback-test/node_modules/loopback/node_modules/async/dist/async.js:920:20)\n at restApiHandler (/Repos/loopback-test/node_modules/loopback/server/middleware/rest.js:63:11)\n at Layer.handle [as handle_request] (/Repos/loopback-test/node_modules/loopback/node_modules/express/lib/router/layer.js:95:5)\n at trim_prefix (/Repos/loopback-test/node_modules/loopback/node_modules/express/lib/router/index.js:312:13)\n at /Repos/loopback-test/node_modules/loopback/node_modules/express/lib/router/index.js:280:7\n at Function.process_params (/Repos/loopback-test/node_modules/loopback/node_modules/express/lib/router/index.js:330:12)"
}
}
What I have tried:
- Setting up and connecting to a database, as per the instructions in the Toptal post.
- Tried the API project and sample Notes project, when setting up the Loopback project (step 2 above).
- Compared the project to another Loopback project I'm working on, where the REST API works. Unfortunately, I'm not experienced enough to spot any significant difference.
- Implement a custom model (as seen in both the Toptal post and Youtube video) and trying to access it via the REST API.
- Searched for the raiseUrlNotFoundError. The best hit is this issue on GitHub which provides a (dead) link to a SO question.
- Tried running the project on a different port than the standard 3000, in case there was some issue with other projects.
- Setup automigration of the common models to the datebase. Added a user and an accesstoken to the database and tried to use that accesstoken in the REST API Explorer.
I run Mac OS X, version 10.11.6. I have Node, npm and other necessary tools installed.
What am I missing, or what can I do to avoid getting the raiseUrlNotFoundError, and access the REST API for my project?