Web750 Support Articles and How-to guides:


Node.js Made Easy: Plesk Windows Control Panel


Introduction


Setting up and deploying Node.js applications has become integral to modern web development. Plesk for Windows Control Panel offers a convenient and user-friendly platform for hosting and managing web applications, including those built with Node.js. This guide will help you get Node.js up and running on Plesk for Windows so you can easily publish your web applications.


Whether you're a seasoned developer or new to web hosting, this guide aims to provide comprehensive step-by-step instructions for successfully launching your Node.js application. We'll cover everything from the initial setup of your application parameters to managing dependencies, configuring environment variables, and ensuring the security and scalability of your application.


By the end of this guide, you'll have a clear understanding of how to harness the power of Plesk to bring your Node.js application to life, making it accessible to users worldwide.


So, let's dive into the world of Plesk and Node.js and embark on a journey to create and manage web applications that deliver exceptional experiences to your audience.


How to install a Node.js application on the website in Plesk


Uploading the application's files


Uploading a Node.js application to your website requires transferring the application's files to the server. This transfer can be accomplished using either FTP or the File Manager tool.


Using FTP (File Transfer Protocol):


Download an FTP Client: Choose an FTP client such as FileZilla, WinSCP, or Cyberduck.


Connect to the Server: Launch the FTP client and connect to your server using the provided hostname, username, password, and port.


Navigate to Application Directory: On the server, navigate to the directory where you want to upload your Node.js application.


Upload Files: In the FTP client, select the local files from your computer that you want to upload and drag them to the server's directory.


Monitor Progress: Observe the progress of file uploads. Once completed, your Node.js application's files will be on the server.


Using File Manager:


Access Control Panel: Log in to your hosting control panel (e.g., cPanel, Plesk).


Find File Manager: Locate and access the File Manager tool within your hosting control panel.


Navigate to Application Directory: Browse to the directory where you want to upload your Node.js application's files.


Upload Files: Use the File Manager's "Upload" button to select files from your local computer. Follow the prompts to complete the upload.


Monitor Progress: Observe the progress of file uploads. Once done, your Node.js application's files will be on the server.


How to set up and run the Node.js application with Plesk control panel:


After uploading your Node.js application's files to the server, you'll need to follow these steps to set up and run your application:


Access the Server:


Use SSH or the command-line interface your hosting provides to access the server.


Navigate to the Application Directory:


Use the terminal to navigate to the directory where you uploaded your Node.js application.


Install Dependencies:


To install the necessary dependencies indicated in the package for your application, run the npm install—file in JSON.


Configure Environment Variables (if needed):


If your application uses environment variables, configure them in the server environment.


Start the Application:


Launch your Node.js application using the appropriate command. This might be something like npm start or node app.js.


Monitor Application Logs:


Keep an eye on the terminal for errors or logs your application generates. That will enable you to recognize problems and monitor their development.


Open Application in Browser:


Once your application is running, open a web browser and navigate to the URL hosted by your application. That could be the domain or IP address followed by the appropriate port.


Testing and Validation:


Test different features of your application to ensure it's functioning as expected. Check for any errors or unexpected behavior.


Keep Application Running:


Depending on your server setup, keep the terminal session running for your application to remain active. Alternatively, consider using tools like PM2 or Forever for process management and auto-restart.


Configure Domain/URL (if applicable):


If you want your application accessible via a specific domain or URL, configure the web server (e.g., Nginx or Apache) to proxy requests to your Node.js application.


SSL/HTTPS Implementation for Node.js Applications


Implementing SSL (Secure Sockets Layer) and enabling HTTPS (Hypertext Transfer Protocol Secure) for your Node.js application is essential to ensure secure communication between users and your server. It encrypts data transmission, safeguards sensitive information, and boosts user trust. Here's how to implement SSL/HTTPS:


Obtain an SSL Certificate:


Use a free SSL certificate from Let's Encrypt or buy one from a reputable Certificate Authority (CA). A private key (.key) and a certificate file (.crt) are required.


Configure SSL in Node.js:


Within your Node.js application, you must configure the server to use the SSL certificate and private key. That typically involves reading the certificate and critical files and setting up an HTTPS server instance.


Install Dependencies:


If using a custom implementation, ensure the necessary Node.js packages (e.g., https, fs) are installed.


Create HTTPS Server:


Create an HTTPS server using the HTTP module, providing the SSL certificate and private key as options.


Redirect HTTP to HTTPS (Optional):


To enforce HTTPS, you can set up an HTTP server that redirects all requests to the HTTPS version.


Update Application URLs:


Update your application code to use HTTPS URLs for assets, links, and resources. That prevents mixed content warnings.


Configure HSTS (HTTP Strict Transport Security):


Optionally, configure HSTS headers in your application to instruct browsers to always use HTTPS, enhancing security.


Testing and Debugging:


Test your HTTPS setup thoroughly, verifying URL redirects and ensuring all assets load securely over HTTPS.


Monitor Certificate Expiry:


Please keep track of your SSL certificate's expiration date and renew it in advance to prevent interruptions.


Update DNS Records:


Ensure your domain's DNS records point to the correct IP address, considering HTTP and HTTPS.


Keep Upgrades and Patches:


Stay updated with the latest SSL/TLS standards and apply security patches when necessary.


Implementing Auto-Restart for Node.js in Plesk


Enabling auto-restart for your Node.js application ensures it continues running even after crashes or failures, improving uptime and user experience. Here's how to set up auto-restart:


Install Process Manager:


Choose a process manager like 'pm2' or 'forever' to handle automatic restarts. Utilize npm to perform a global installation: 'npm install -g forever' or 'npm install -g pm2'.


Navigate to the Application Directory:


The terminal will navigate your Node.js application's directory.


Using PM2:


For 'pm2', start your application: 'pm2 start app.js' (replace 'app.js' with your main application file).


PM2 automatically monitors your application and restarts it if it crashes.


Using Forever:


For 'forever,' start your application: 'forever start app.js'


Forever monitors your app and restarts it on crashes.


Setting Up Process Manager for Production:


Configure the process manager to run in production mode:


'pm2 start app.js --env production' or 'forever start app.js –prod.'


View Process Status:


For pm2, view process status: pm2 status.


For forever, view process status: forever list.


Auto-Start on System Reboot (Optional):


Configure pm2 or forever to start your app automatically when the server reboots.


Logging and Monitoring:


Both managers offer logging and monitoring features to track application health and events.


Updating and Stopping:


For 'pm2', update your app:


'pm2' update and stop 'pm2 stop app'.


For 'forever,' update: 'forever' update and stop: 'forever stop the app'.


Fine-Tuning:


Configure options like memory limits, restart delays, and log outputs according to your application's needs.


Testing Auto-Restart:


Test by intentionally causing a crash. The process manager should detect the impact and automatically restart the app.


Conclusion:


In the rapidly evolving web development landscape, Node.js has emerged as a powerhouse for building scalable and efficient applications. Plesk for Windows Control Panel paves the way for a smooth Node.js journey, offering a user-friendly and comprehensive solution for installation and setup.


With Plesk's intuitive interface and robust features, web developers can effortlessly deploy Node.js applications, harnessing the full potential of this versatile runtime.


From simplified installation to automated configuration and effortless management, Plesk empowers users to focus on their code while ensuring a seamless deployment experience.


By leveraging Plesk's capabilities, you can accelerate your Node.js projects, streamline development processes, and enhance your online presence, keeping pace with the dynamic digital landscape.


Useful links / Resources


  • How to Host Node.js Applications (Plesk)

  • Using Node.js (Plesk)

  • Hosting Node.js Applications (Plesk)

  • Support Article (in Spanish)

  • Support Article (in Portuguese)

  • Go back to Web750