How does javascript-Nodejs program run on the server?

Source: Internet
Author: User
Tags node server
Previously, it was developed locally, directly accessing the directory where the program is located, and then nodeserver. javaScript can be run. now I have a server directory bukemall. comgaoqiang... in this way, I can access my main program file, but how can I start it? I have been working locally and directly go to the program directory. then node server. js can run. now I have a server directory.
Http://bukemall.com/gaoqiang...

In this way, I can access my main program file, but how can I start it?

Reply content:

I have been working locally and directly go to the program directory. then node server. js can run. now I have a server directory.
Http://bukemall.com/gaoqiang...

In this way, I can access my main program file, but how can I start it?

You can also execute node server. js on the server;

However, execute the command on the server and switch it to the backend:

Nohup node server. js> myLog. log 2> & 1 & // replace node server. js

In this way, your program will be switched to the background for execution, and a myLog. log and log will be generated. related errors will also be recorded in the log;

Of course, there are some advanced tools like pm2, which will be more convenient .... However, the general purpose is to allow your program to run on the server in the background;

Google pm2

Go to the program directory on the server, and thennode server.jsYou can.
A locally developed computer can also be considered as a server.

Samenode server.jsYou only need to configure the port when the server can be accessed. if port 80 is not occupied, use port 80 directly. if port 80 is occupied, use other ports. If nginx already exists, a second-level domain name is used for reverse generation. Open the firewall to allow access directly using other ports. To restart the server, you can use the pm2 mentioned above to automatically restart the node.

Thank you for your invitation. we can see that the weekend is over.

After reading your source code,

I don't know what your chatServer is doing .. It seems like an example of websocket testing for im chat.

You only need node server. js to start it, and you need to enter your Directory. if not, add node xxx/server. js to the front.

Xxx indicates your Directory

I personally suggest using supervisor to monitor code, automatically restart, and print log errors, which is suitable for development and debugging.

Reference github https://github.com/petruisfan...

After installation, the supervisor -- debug server. js is started.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.