services:nodeserv
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
services:nodeserv [2024/08/12 13:13] – jas | services:nodeserv [2024/08/12 14:01] (current) – removed jas | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Nodeserve User Documentation ====== | ||
- | |||
- | Nodeserve allows you to make NodeJS apps available for others to access on the web. Follow these instructions for enabling access to your NodeJS apps on the web. | ||
- | |||
- | 1. Create a directory in your home directory called " | ||
- | |||
- | % mkdir ~/nodejs | ||
- | |||
- | 2. Create a subdirectory inside the " | ||
- | |||
- | For example, if you will be hosting an application " | ||
- | |||
- | % mkdir ~/ | ||
- | |||
- | 3. Develop your NodeJS app in its respective app directory. | ||
- | |||
- | 4. For each app, create a package.json file using the //npm init -y// command. | ||
- | |||
- | 5. Let the server know that you want your app to be accessible on the web using the " | ||
- | |||
- | The nodeserve command has 3 options - add, del, and list: | ||
- | |||
- | < | ||
- | 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 stop an app from being web accessible: | ||
- | |||
- | < | ||
- | % 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. | ||
- | | ||
- | 6. Visit your app on the web by visiting: | ||
- | |||
- | The web server will look up the port number of your app, and set the port number in the PORT environment variable. | ||
- | |||
- | ====== Helpful Hints ====== | ||
- | |||
- | 1. Each user can use the //nodeserve add// command to add 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 // | ||
- | |||
- | For example: | ||
- | |||
- | < | ||
- | const port = process.env.PORT; | ||
- | server.listen(port, | ||
- | console.log(`Server is listening on port ${port}`); | ||
- | }); | ||
- | </ | ||
- | |||
- | 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. | ||
- | |||
- | 5. Since your application is running on the server, you don't have direct access to view the console, but that doesn' | ||
- | |||
- | < | ||
- | const fs = require(' | ||
- | const logFile = fs.createWriteStream(`${__dirname}/ | ||
- | const logStdout = process.stdout; | ||
- | |||
- | // Override console.log to write to the file and stdout | ||
- | console.log = function (...args) { | ||
- | logFile.write(new Date().toISOString() + ' - ' + args.join(' | ||
- | logStdout.write(new Date().toISOString() + ' - ' + args.join(' | ||
- | }; | ||
- | </ | ||
services/nodeserv.1723482791.txt.gz · Last modified: 2024/08/12 13:13 by jas