Cannot GET an Express Route - javascript

I am working with ExpressJS route and everything works not until I added a route in which I get the error message,
Cannot GET /api/users/abc
using Postman.
Below are images that describe the challenge right now.
From my server.js file
To my userRoutes.js file
Every route works fine but /user_stats route doesn't. My approach to debugging the problem is to create an /abc route but to no avail, I got this HTTP response from Postman
Now the question, what might have gone wrong in my code?

It seems after adding the route you haven't started the server. So, to make sure every time you made any changes to the files get reflected in the server build, you should install nodemon and make it run.
npm install --save-dev nodemon // only for dev
To run :
nodemon [your node app]
For more details check this, how you can configure your server to run the build files.

Related

Gatsby development server stops working when repo is created on github. Sanity, Gatsby Error

I received a github repo backup from somebody elses account. The project is running gatsby, sanity cms and is hosted via netlify. When I extract the archive and saving the folder locally, I am perfectly able to get the gatsby development server runnning just by doing "yarn install" and "yarn gatsby develop".
However, when I create a new repo and import the project to my github account, the development server is not running anymore. We tried it on several machines and we always get the same error in terminal trying "yarn gatsby develop".
success open and validate gatsby-configs - 0.131s
success load plugins - 2.486s
success onPreInit - 0.038s
success initialize cache - 0.009s
success copy gatsby files - 0.091s
info [sanity] Fetching remote GraphQL schema
ERROR #gatsby-source-sanity_drafts.10003
[sanity] The token specified is not valid or has been deleted
How is that possible? I tried to fix this for days but I don't get it. The only differnce between being able to run the dev server and this error is to save the code to github... Is it maybe some sort of routing problem in the gatsby-config.js?
Would appreciate your help a lot!
It seems that you are missing the environment variables in your new projects so your Sanity configuration is not valid, hence Gatsby is not able to fetch the data from the sources.
There should be a .env.development or .env.production files in your original code placed in the root of the project.

ExpressJS webseite works local but returns 403 Forbidden online

I'm trying to get this example ExpressJS app running on my server.
Offline (on localhost) it is working correctly after running npm start.
I uploaded all files, installed everything through npm install, started the nodemon through SSH npm startand got the App Running response.
If I try now to open the URL of the website it returns 403 Forbidden.
What do I need to change to make it work?
(It's my first time working with ExpressJS - maybe it's just a noob issue. Could this be a HOST or PORT issue?)

Git return "'pull' is not a git command. See 'git --help'" from remote on Windows 10

I have a bonobo server on my server that is running windows 10.
I'm trying to link a new hook on "Update", so the files from the node development server can get updated directly from git.
I tried to do so using a cmd file, examples to follow:
update file in hooks
cmd //C "start C:\webServer\node\testServer\update.bat"
update.bat on the same folder on testServer
set PATH=%PATH%;C:\Program Files\Git\cmd\git.exe
cd C://webServer/node/testServer
git pull
That was returning the following error:
git: 'pull' is not a git command. See 'git --help'
I did some research and found out this post "git pull" broken where they talk about using -exec-path on Mac, I tried to search the equivalent in Windows and found out some variables for path related issues, tried them an none of them worked, also tried to reinstall git without any other result, at that point I was tired of it and I tried to use a node library, simple-git, that allows me to do a pull request using node specifying the path! I tried it on the server, and it worked! (I will attach the code of the file below) so I thought to try it from the remote server, but then I got the same error again, pull is not a git command, I tried to call the node file in different ways, I tried some python script to run a cmd command that runs the node server, I tried using bat and sh files, even using node to run another instance of node, and nothing worked, it always returns pull is not a git command :/
Node simple-git code
require('simple-git')("C:\\webServer\\node\\testServer")
.pull(function(a,b){
console.log(a,b); //for debug
})
Has additional information, git is properly set up as an environmental variable and I can access it without problems from the server, this issue only happens when trying to execute the pull from the hooks!
If anyone can give me some tips on what to try that would be awesome, thanks!

cannot start nodejs web api hosted in Azure

Learning nodejs and started to created my own restful API using restify.
I have created a very simple server.js file which contains basically a hello world type example starting up like:
server.post('/api/messages', servicemanager.verifyFramework(), servicemanager.listen());
server.get(/.*/, restify.serveStatic({
'directory': '.',
'default': 'index.html'
}));
server.listen(process.env.port || 3978, function () {
console.log('%s listening to %s', server.name, server.url);
});
which works fine locally. I cant hit http://localhost:3978 and I can test my API calls just fine calling http://localhost:3978/api/messages.
I have deployed my code into bitbucket and now I want to host these APIs in Azure using App Services.
My project structure is like so:
/topfolder
-/myproject
-/node_modules
-/node_modules...
server.js
package.json
index.html
When I setup the new app service in Azure, I can see that the deployment receives the code from BB, but the service never responds to my requests.
I have setup the home path of the app to live in: /site/wwwroot/topfolder/myproject and I can see the index.html when I navigate to http://myproject.azurewebsites.net so thats good.
I actually get a 404 error:
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
There are heaps of examples of how to setup continuous deployment using bitbucket and for the most part, they all seem to work, but my server.js file doesnt seem to be the getting called or starting up.
How can I debug whats going on here?
Is the packages.json file used in this scenario by Azure?
Thanks.
As the root directory path of the application hosted on Azure App Services, is D:\home\site\wwwroot. And about the nodejs application, the Azure fabric will find the entrance script in root directory like server.js. And the requests are handled via web.config in root directory. If there is missing server.js or web,config file, you will occur 404 error.
You can try to modify or your application's structure, like to:
-/node_modules
-/node_modules...
server.js
package.json
index.html
Then, you deploy your application to Azure via GIT or from BB, the Azure deployment task will run command npm install and generate the web.config wile in the root directory.
Any further concern, please feel free to let me know.

Run Meteor from within a folder

I've run meteor build to create my bundle, uploaded to the server, it runs fine, however the .css and .js paths are wrong, as it's using the root url. I need to run this from within a /project folder. Again it's running, but 404 on the files as they're not prefixed with /project.
eg. http://domain.com/65d054cb90ff094804072528d222178ddbf625e22.js?meteor_js_resource=true 404 (Not Found)
needs to be http://domain.com/project/65d054cb90ff094804072528d222178ddbf625e22.js?meteor_js_resource=true
I've tried using ROOT_URL=http://domain.com/project node main.js, that gives an unknown path error, i've also tried using Meteor.absoluteUrl('project', {}); in conjuntion with rooturl but again, no avail.
Any of you fine people have any ideas? :) Thanks!
PS. It's running on an apache server with ProxyPass, if that's of relevance.
You could instruct your apache to redirect those calls with a ProxyPassMatch, such as:
<LocationMatch ^/(.*)meteor_js_resource=true$>
ProxyPassMatch http://localhost/project/$1meteor_js_resource=true
</LocationMatch>

Categories