The PM2 page allows you to run Python or NodeJS applications from within the OpenPanel interface.
To create a new application click on the 'New Application' button.
In the form set:
And click on the 'Create' button.
For python applications you need to set the Type to Python so that PM2 uses the --interpreter flag.
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():
return "Hello world!"
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)
Navigate to your project directory: Open Web Terminal or connect via SSH to the server and navigate to the directory where your project is located. You can use the cd command to change directories.
cd path/to/your/project
Check for package.json file: Make sure that your project has a package.json file. This file contains metadata about your project and the list of dependencies. If you don't have one, you can create it by running:
npm init
Follow the prompts to set up your package.json file.
Install dependencies: Run the following command to install the dependencies listed in your package.json file:
npm install
const http = require('http');
const server = http.createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello, World!\n');
});
const port = process.env.PORT || 3000;
server.listen(port, () => {
console.log(`Server is running on port ${port}`);
});
The PM2 page displays a list of all current NodeJS and Python applications.
Currently only the following actions can be performed for existing applications in the PM2 page:
To restart an application *(force stop and start it immediately) click on the 'Restart' button:
This will immediately stop the pm2 process for the applicaiton and start again the startup script.
To stop the application simply click on the 'Stop' button. This will immediately stop the process but leave the Nginx proxy to the port.
To completely remove an appliaiton click on the 'Delete' button. This will immediately stop the process and delete the Nginx proxy to the port.