Getting 404 on sails project when reaching through machine name - node.js

I am pretty new to sails module on node.js
I created a basic web-app and it launches good on
http://localhost:8081/test
but when I try to access with my machine name like
http://mymachinename:8081/test
it goes 404 page. I also tried to access from another PC in same domain and same 404 error.
I expect both requests should return 200 response.
Am I missing something?

Here is a little information and some suggestions. Here I am on MAC OS X.
First, yes it should work out of the box:
$ sails new app && cd $_ && npm install
$ sails lift --port 1338
http://127.0.0.1:1338/
http://192.168.0.5:1338/
http://mymachine.local:1338/
are all equivalent (loopback, my local IP, my local machine name respectively).
Try a port scan and see if the port you think it is running on is actually running or else already occupied.
On Mac OS X.
lsof -i :1337
Perhaps try starting on a different port:
sails lift --port 1338 (i did this for the above)
Did you install sails globally? If so, you could try uninstalling and reinstalling:
npm uninstall -g sails
npm install -g sails
If you are still having problems, they are local and very unlikely specific to SailsJS. Do usual troubleshooting for network / port related issues locally etc.
Finally, to gain access for other users to your local machine, i usually use ngrok. Ngrok exposes your localhost to the web - example:
$ npm install ngrok -g
$ ngrok http 1338
See this example usage:
In the above example, the locally running instance of sails at: localhost:1338 is now available on the Internet served at: http://840fa6c4.ngrok.io

Related

Ember Server: "Port 4200 is already in use", when no process runs on 4200

When running my ember application with ember serve -e local I get:
Port 4200 is already in use.
Which is weird because no application is running on 4200. I tried to open a dummy HTTP server on 4200 with http-server and it works just fine. It also works when I specify the port via a command line flag ember serve --port 4200.
Some things I've tried:
Restarted my computer.
Removed the node_modules.
Remove the ember tmp directory.
Disabled my firewall.
Tried with disabled wi-fi.
Any thoughts?
I'm running on masOS High Sierra 10.13.6 with the following versions:
node: 8.11.3
ember-cli: 2.18.2
npm: 5.6.0 (also tried with 6.3.0)
Also useful to know:
I have other ember applications running on my computer just fine.
I started to have this problem only recently.
In the past, macOS would keep asking me about authorizing incoming traffic whenever an app was opened, but now it stopped asking me.
I had this issue and tracked it down to using a string vs. integer for port in .ember-cli.
// .ember-cli
{
"port": 8080, // works
"port": "8080", // throws the error mentioned above
}
Not sure if this is the cause for others with this error. As mentioned, first thing is to make sure nothing else is actually running on that port. But OP had already checked that, and so had I.
After further investigation, it seems that the problem is not coming from macOS, but from something messed up in the dependencies causing ember-cli to fail...
It's not quite clear what is causing this, and I will try to post any additional information here, but for now if you happen to encounter this problem, just pass the port value directly to ember-cli like so:
ember serve --port 4200

Intercept outgoing HTTP requests to npmjs.org, etc

I am looking to create a locally running Node.js server that can intercept outgoing requests to the NPM registry (npmjs.org, or whatever).
Is that what a reverse proxy is?
Basically what I would like to do is create a locally running NPM registry - this is for use with locally running Docker containers. Normally I would just use npm link for local development. But when testing libraries using Docker locally, using npm link for that becomes hard to impossible
I know there are some libraries out there that set up a local NPM registry, but I am looking to do this from scratch so I can set it up for my use case. Essentially I want to tarball packages that exist on my filesystem each time an npm install request comes in.
I started experimenting with:
npm config set registry http://localhost:3440
but when I subsequently did an npm install, it didn't seem to hit my locally running server, just went to registry.npmjs.org like normal.
I also tried modifying /etc/hosts
before:
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
after:
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
registry.npmjs.org localhost:3440
but my local server listening on port 3440 did not seem to intercept any traffic.
That's not a reverse proxy, but that's a forward proxy. And you'll effectively have to use npm config set proxy to use it from npm call.
The main tool used for such proxy is usually squid proxy. And I'm pretty sure you can build more robust and feature-full service using some well known forward proxy tools instead of a custom nodejs tool.
Then you'll have to check where this service is running (on the same docker? on another docker? on your host?). The address you set for npm, in npm config set proxy must be resolvable from inside the container running npm (but it may differ between commands running on the Dockerfile step and commands running in a bash session after that build).

Node web server not visible externally, but Python is (MacOS)

I'm just starting to build an Ionic 2 app, but I can't get it working on my mobile device.
Python (works)
To demonstrate that the phone can see the host, I tried a Python server:
$ python -m SimpleHTTPServer 8000
Serving HTTP on 0.0.0.0 port 8000 ...
If I go to http://192.168.8.101:8000 on my phone, it connects fine and displays the directory listing.
Node (fails)
However, when I start Ionic:
$ ionic serve -p 8000
[...]
[INFO] Development server running
Local: http://localhost:8000
External: http://192.168.8.101:8000
I can load it in my host's web browser, but I can't see it from my phone nor another computer (it times out). I also tried a basic node server:
$ npm install http-server -g
$ http-server -p 8000
Starting up http-server, serving ./
Available on:
http://127.0.0.1:8000
http://192.168.8.101:8000
With the same result as Ionic: accessible from the host, but not from the phone.
Is there something blocking the request? Or is there some Node configuration I'm missing? I'm new to both Mac OS and Node, so I don't know where to look.
Embarrasingly, this turned out to be a firewall issue. In System Preferences > Security & Privacy > Firewall > Firewall Options, Node was explicitly set to deny incoming connections:
Changing it to Allow has fixed it. Phew!
Just execute ionic address and you'll get an IP address in your command line. Try with that ipaddress:port number from your mobile which will enable you to access your site from your phone.
Just incase if the ionic address command doesn't return anything, you need to execute the below command to point it to your ip,
ionic serve --address YOUR_IP_ADDRESS
Hope this helps!

Accessing my node.js by others?

I have successfully launched my node.js server, and can access it through http://localhost:3000
How do I allow others see my development server? I do not have external IP.
For quick sharing in development stage there is a special NPM module called localtunnel. Do not use this method in production website due to security concerns.
Using localtunnel after you installed it (npm install -g localtunnel):
lt --port 3000
It shall output you the externally accessible URL after running the command, share this url with your friends.

socket.io example not working - Windows

Im using Node.js 0.6.2 on Windows 7
I managed to get the dependencies solved on Win7 for socket io, now when i launch one of the example apps it doesnt throw any errors.
however, for the IP and listener it reports its listening on , when i launch that in the browser, the connection times out.
Any ideas?
I've tried setting app.listen to different ports and IP addresses, but no luck.
Just for reference, i've tried the famous "hello world" Node.js example which works fine.
Things i've already checked
Other services running on the same ports or same listener IP
Different IP addresses and ports
Firewall / Port blocking
Restarting of the machine
dependencies in node_modules
Different browsers
Telnetting to the listener port (which shows a response so the listener must be working?)
So this works for me (running msysGit and node.js, both latest versions; both Windows installers):
$ cd c:\msysgit\msysgit\cmd
$ git clone git://github.com/ry/node_chat.git
$ cd node_chat
$ "c:\progra~1\nodejs\node.exe" server.js
I can open 127.0.0.1:8001 now and run it. The fact that you have to cd into the directory is a bug in node_chat, same behavior is in OS/X.
I managed to solve this problem with some outside help.
I downloaded Node 0.6.3 which comes with NPM.
I created a test folder and then ran NPM Install socket.io express within the test folder and then tested the example app from the Socket IO website in the how-to-use section.
Socket IO emitted the events fine and it all seems to be working well. Thanks everyone for the help and guidance.

Resources