In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains the "deployment of Node applications choose Heroku or Now.sh", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "deploy Node applications choose Heroku or Now.sh"!
Deploy with Heroku
In order to be able to deploy applications to Heroku, programmers must register on Heroku and install Heroku CLI for the machine.
Before you begin, you need to add some code to Procfile. Because Heroku will use this file to determine how to execute the uploaded code.
If you add the following code to the file, Heroku knows what command should be executed to start the application:
Once this is done, try to log in by entering heroku login from the terminal. Heroku will require login credentials.
Next, navigate to the root directory of the project and enter the command: heroku create. This creates an application on Heroku that is ready to receive the source code for the project. The application name on Heroku is created at random.
To deploy the code to Heroku, simply use git push heroku master. Programmers can use the heroku open command to access the application, which opens the generated URL.
Promote changes to Heroku
Following the normal Github process can drive change:
Useful Heroku commands
Make sure that at least one instance of the application is running: heroku ps:scale web = 1
Because you are using a free platform, it is not possible to extend the application. However, the scale can be reduced, so the instance of the application that is not running: heroku ps:scale web = 0.
View the latest logs (streams) in the chronological order in which Heroku is generated: heroku logs-- tail
You can display only the application log. The application log is the output of the console.log () statement in the code, which can be viewed using the following statement: heroku logs--source app-name
Heroku offers the possibility of running an application on a local / / localhost:5000: heroku local web
List all Heroku applications: heroku apps
Delete deployment: heroku apps:destroy--app app-name
Add owner (account) to access the application: heroku access:add me@email.com, delete heroku access:remove
Heroku environment variable
If you use .env files locally, you may need to use other environment variables for your Heroku deployment. You can use heroku config to set them: heroku config:setPORT=3001. These values override the variables set by the user in the .env file.
To see all the defined Heroku environment variables, simply use heroku config. If you want to delete an environment variable such as PORT, use heroku config:unset PORT.
A freely available version
Allow up to five Heroku applications
512 MB RAM
Not available for upgrade, only one application instance can be run at the same time
Go to sleep after being idle for 30 minutes
Randomly generate application names
Metrics for memory usage, response time, and available throughput, but custom metrics cannot be added
Deploy using now.sh
Now.sh focuses on the developer experience (DX), which is a unique approach. They try to provide flexible tools that are very easy to use. Now.sh is part of some of the tools developed by Zeit.cowhich.
For simplicity, we will install Now.sh CLI only through npm:
Next, you need to register so that you can use it in the console. Both login and registration take place in login page. Each time you log in, you must confirm the login attempt through email authentication. Once confirmed, it will be redirected to the dashboard and programmers can view logs and deployments.
To get started, just type now in the console. The console will prompt for an email, fill in the correct email, and verify the email by clicking.
After logging in, let's take a look at the startup script in package.json. Now.sh uses this to start the application. This is what the scripts field looks like:
Let's start deploying the code to now.sh. Make sure you are in the root directory of the code example. To begin the deployment process, simply click now. I think you can see developer experience, everything can be executed with a keyword now! If you make changes to the application and want to redeploy the application, simply click now in the console.
The URL for the application can be found in the console log, and more regular logs about deployment or other commands can be found on the dashboard.
Customize and define environment variables
One way to customize the Now.sh deployment is to use the now.json file. However, because the package.json file is already used, you can add the desired customizations under the now key. This configuration allows you to customize application names and aliases, set environment variables, specify deployment types, and define engines.
Programmers can also set the environment variable through CLI: now-e NODE_ENV = "production"-e PORT = "3001".
If you want to provide a dotenv file, you can set the option-- dotenv, and if you want to use .env. Production instead of .env?, consider using-- dotenv=.env.production. Finally, you can add the production dotenv file to your package.json.
Useful Now.sh commands
You can add an alias to the deployment: now alias deploy-url aliasname
List all deployments with their only code: now ls
Delete deployment: now rm unique-code
Force new (if there is a problem): now-f
Extend web applications (up to 3 free editions): now scale deployment-url3. Sometimes it is not easy to predict traffic. Now.sh allows you to set the minimum and maximum values for automatic scaling: now scale deployment-url min max.
Monitoring log
Log output can be obtained by the following command: nowlogs [deployment-url | deployment-id]. More advanced logging is also possible.
Now logs-a-q "GET"-n10deployment-url: displays 10 latest logs containing the word GET.
Now logs--since=20171028: shows all logs for October 28th, 2017 (ISO 8601 format)
You can also access the log by clicking the application in the Now.sh dashboard.
Now.sh 's OSS Plan
The OSS program is available free of charge and provides the following:
Bandwidth: 1GB
Log storage up to 100MB
Unlimited deployment possibilities
Concurrent instances are limited to 3
Custom fields are not supported
Maximum file size: 1MB
No automatic extension support
Compare
Both Heroku and Now.sh provide good functionality. Now.sh pays more attention to the developer experience by providing an easy-to-use CLI. On the other hand, Heroku pays more attention to visual recording, especially monitoring with metrics.
Personally, I prefer simple Now.sh, which now requires only a keyword now for (re -) deployment. For Node applications, I like to add the now attribute to the .package.json file to customize the Now.sh deployment. There is no need to add additional files as required by Procfile Heroku.
It's hard to choose between the two platforms, but it only depends on your preferences and needs. In addition to some of the support available for the free version above, Now.sh may be even better in terms of ease of use!
Thank you for reading, the above is the "deployment of Node applications choose Heroku or Now.sh" content, after the study of this article, I believe you on the deployment of Node applications to choose Heroku or Now.sh this question has a deeper understanding, the specific use also needs to be verified by practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.