services:nodeserve
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
services:nodeserve [2024/08/12 14:03] – created jas | services:nodeserve [2024/08/13 11:48] (current) – [Nodeserve] jas | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Nodeserve | + | ====== Nodeserve ====== |
- | Nodeserve | + | The Nodeserve |
- | 1. Create a directory in your home directory called " | + | 1. Create a directory in your home directory called " |
% mkdir ~/nodejs | % mkdir ~/nodejs | ||
Line 13: | Line 13: | ||
% mkdir ~/ | % mkdir ~/ | ||
- | 3. | + | 3. |
- | 4. For each app, create a package.json file using the //npm init -y// command. | + | % cd ~/nodejs/app1 |
+ | % npm init -y | ||
+ | |||
+ | 4. Develop your app. You can use **npm install** to install whatever packages you need. | ||
- | 5. | + | 5. |
- | The nodeserve command has 3 options | + | 6. Allocate a port number for your app using the **nodeserve** command. |
+ | |||
+ | Each Node.js application must be allocated a unique port number to communicate with the web server. Ports act as channels for data to flow in and out of your app. We allocate a specific port for your app to ensure it runs smoothly without conflicts with other apps. This avoids issues that can arise from choosing an arbitrary port, which might already be in use by another service or application. | ||
+ | |||
+ | The nodeserve command has 3 options | ||
< | < | ||
- | nodeserve add <appname> to add an application | + | Usage: |
- | nodeserve del <appname> to delete | + | |
- | nodeserver | + | nodeserve |
</ | </ | ||
- | For example, to let the server know you want " | + | A few notes on app names: |
+ | |||
+ | * < | ||
+ | * < | ||
+ | |||
+ | In addition, each user can be allocated a maximum of 10 port allocations. | ||
+ | |||
+ | For example, to get a port allocation for an app " | ||
< | < | ||
% nodeserve add app1 | % nodeserve add app1 | ||
- | App ' | + | Port 4000 has been allocated for app ' |
</ | </ | ||
- | You can list the apps that you've made web accessible: | + | You can list the port allocations for your apps: |
< | < | ||
% nodeserve list | % nodeserve list | ||
- | List of apps for user 'jas': | + | List of app port allocations |
app1 -> Port 4000 | app1 -> Port 4000 | ||
</ | </ | ||
- | You can stop an app from being web accessible: | + | You can also delete a port allocation for an app: |
< | < | ||
% nodeserve del app1 | % nodeserve del app1 | ||
- | App ' | + | Port allocation for app ' |
</ | </ | ||
- | NOTE: Deleting an app simply tells the Node web server that you don't want it to make your app web accessible. | + | 7. Visit your app on the web by visiting: |
- | + | ||
- | 6. Visit your app on the web by visiting: | + | The web server will look up the port number allocated to your app, and set the port number in the PORT environment variable. |
- | The web server will look up the port number of your app, and set the port number in the PORT environment variable. | + | A few additional notes: |
+ | * Your web application will run as your user ID. It can read and write files in your home directory. | ||
+ | * Any additional query arguments added to URL will be passed to your application - so, https:// | ||
+ | |||
====== Helpful Hints ====== | ====== Helpful Hints ====== | ||
- | 1. Each user can use the //nodeserve add// command to add up to 10 applications. | + | 1. Each user can use the **nodeserve add** command to allocate a port for up to 10 applications. |
2. When developing your code, please do not hard-code the port number allocated to you via the nodeserve command in your app. Instead, your code should read the port number from the environment variable // | 2. When developing your code, please do not hard-code the port number allocated to you via the nodeserve command in your app. Instead, your code should read the port number from the environment variable // | ||
Line 73: | Line 90: | ||
3. In order to ensure that the server is not overloaded with applications which do not need to be running all the time, your application will automatically shutdown after approximately 10 minutes of inactivity. | 3. In order to ensure that the server is not overloaded with applications which do not need to be running all the time, your application will automatically shutdown after approximately 10 minutes of inactivity. | ||
- | 4. Sometimes, you may need to terminate your application before the period of inactivity expires. | + | 4. Sometimes, you may need to terminate your application before the period of inactivity expires. |
- | 5. Since your application is running on the server, you don't have direct access to view the console, | + | 5. Since your application is running on a server |
< | < |
services/nodeserve.1723485788.txt.gz · Last modified: 2024/08/12 14:03 by jas