0

I am using nodejs for web application. In this I am frustrated with continuously firing command "npm start" when applying small changes on any files.

Question 1 : Is there any way for how to keep automatically call my "npm start" without opening command prompt?

Question 2 : And also I want to remove this port display in url.

I want like below result, example:

Current url: http://localhost:3200/login Expected url: http://localhost/myprojectname/login

2
  • If you want auto run npm start command after you change the code, there are some modules could solve your problem. like node-dev or superviosr etc.., and second question, if you don't want to display the port in production environment, you can use nginx to do reverse proxy, but if in developments, I don't think it's necessary. Commented Jul 7, 2016 at 6:16
  • The community has discussed begging for ASAP/urgency in questions, and has firmly resolved it is unacceptable. Commented Jul 7, 2016 at 7:38

2 Answers 2

1

node-dev will automatically restart your application whenever you save a code change. Install it with npm install -g node-dev then run your application with node-dev server.js (or whatever the entrypoint file for your project is called if not server.js).

For development, it's easiest to just live with the port in the URL. To get rid of it, you need to run your application on port 80 which requires running as root which is insecure. There are ways to do it (via ngrok iptables, nginx, etc, but most developers opt to just deal with the port in the URL during local development

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you Peter. Let me try to install this package.
Can you tell me how can i upload my nodejs web app live..?
Hi peter i have installed this package. Bit its not working. i am using "npm start" but it gives error
1

Try nodemon module, Nodemon is a utility that will monitor for any changes in your source and automatically restart your server.Perfect for development on local machine, you no longer need to deal with npm start every time when you change the code.It will automatically restart the server and changes will be reflect instantly.

install it globally

npm install -g nodemon

then try to run your app using nodemon app.js instead of npm start or node app.js

If you want to use port 80, you should run your application with root/administrator privileges, and make sure no other service is running on that port another solution is which I strongly recommend is to use nginx server reverse proxy settings .Install nginx server on your machine, Following are the settings that you can apply using nginx reverse proxy to remove any port number you want from the url.

server {
        listen   80;
        server_name yourdomain.com;

        location / {
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header Host $host;
                proxy_set_header X-NginX-Proxy true;
                proxy_pass http://localhost:3000/;
                proxy_redirect http://localhost:3000/ https://$server_name/;
        }
}

Hope this helps you.

1 Comment

@daxter, Great, if your issue has been resolved then +1 the post.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.