services:nodeserv
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
services:nodeserv [2024/08/09 15:31] – jas | services:nodeserv [2024/08/12 14:01] (current) – removed jas | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Nodeserve User Documentation ====== | ||
- | |||
- | Nodeserve allows you to make NodeJS applications available for others to access. | ||
- | |||
- | 1. Create a directory in your home directory called " | ||
- | |||
- | % mkdir ~/nodejs | ||
- | |||
- | 2. Create a subdirectory inside the " | ||
- | |||
- | For example, if you will be hosting two applications " | ||
- | |||
- | % mkdir ~/ | ||
- | |||
- | 3. Develop your NodeJS app in its respective application directory. | ||
- | |||
- | 4. Inside each application directory, create a package.json file. Use the You //npm init -y// command to create the package.json file. | ||
- | |||
- | 5. Let the server know that you want your app to be accessible on the web using the " | ||
- | |||
- | The nodeserve command has 3 options: | ||
- | |||
- | < | ||
- | nodeserve add < | ||
- | nodeserve del < | ||
- | nodeserver list to list applications | ||
- | </ | ||
- | |||
- | For example, to let the server know you want " | ||
- | |||
- | < | ||
- | % nodeserve add app1 | ||
- | App ' | ||
- | </ | ||
- | |||
- | You can list the apps that you've made web accessible: | ||
- | |||
- | < | ||
- | % nodeserve list | ||
- | |||
- | List of apps for user ' | ||
- | app1 -> Port 4000 | ||
- | </ | ||
- | |||
- | You can delete an app: | ||
- | |||
- | < | ||
- | % nodeserve del app1 | ||
- | App ' | ||
- | </ | ||
- | |||
- | NOTE: Deleting an app simply tells the Node web server that you don't want it to make your app web accessible. | ||
- | | ||
- | Each user can add up to 10 applications. | ||
- | |||
- | 6. When developing your code, please do not hard-code the port number allocated to you via the nodeserve command. Instead, your code should read the port number from the environment variable PORT. The system will let your app know which port number to use. | ||
- | |||
- | For example: | ||
- | |||
- | < | ||
- | const port = process.env.PORT; | ||
- | server.listen(port, | ||
- | console.log(`Server is listening on port ${port}`); | ||
- | }); | ||
- | </ | ||
- | |||
- | 7. You can access your app by visiting: | ||
- | |||
- | The web server will look up the port number for your app, set the port number in the PORT environment variable, then start your app running as your user id on the Node web server. | ||
- | |||
- | Other Notes: | ||
- | |||
- | * 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. | ||
- | |||
- | * If before those 10 minutes have expired, you wish to terminate your application (because you've changed it, and you want the web server to re-load it), then simply visit this web page: [[https:// | ||
- | |||
- | * Finally, since you don't have access to the console for your application, | ||
services/nodeserv.1723231882.txt.gz · Last modified: 2024/08/09 15:31 by jas