User Tools

Site Tools


nodejs

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
nodejs [2022/01/20 01:34] – updated with image peteyboynodejs [2022/01/21 01:28] (current) – deleting, I renamed peteyboy
Line 1: Line 1:
-== Setting up a simple Node.js Server == 
  
-You can try Node.js by using your [[meta_port_allocation|Port Allocation]] on the [[metaarray|The MetaArray]] to run your own Node.js server. What follows is a bare-bones 'Hello, World' exmaple tailored for the metaarray: 
-  - go to a project folder in your user folder, say <tt>~/projects/nodejstest</tt> 
-  - use your favorite editor to open a new file called ''app.js'' 
-    *paste the following code into the file: <code>const http = require('http'); 
-     //const hostname = '*put your mkhomepg-selected meta-array domain name here, remove the // at the beginning and delete next line*';  
-     const hostname = 'peteyboy.freeshell.org'; 
-     //const port = *replace this with your UID as port number, uncomment and delete the line below*; 
-     const port = 32056; 
- 
-     const server = http.createServer((req, res) => { 
-     res.statusCode = 200; 
-     res.setHeader('Content-Type', 'text/plain'); 
-     res.end('Hello World, this is node'); 
-     }); 
- 
-      server.listen(port, hostname, () => { 
-        console.log(`Server running at http://${hostname}:${port}/`); 
-        });</code>  
-  - run the server with ''node app.js'' (the ampersand backgrounds the job so you can type other commands at shell) 
-  - check it out with a browser pointed to your metaarray website but at your UID port, for example ''http://me.sdf.org:30099'' 
-    * it should look like {{:screen_shot_hello_node.png?400|browser showing hello, world!}}  
-  - quit the server with ''ctl-c'' 
nodejs.1642642497.txt.gz · Last modified: 2022/01/20 01:34 by peteyboy