User Tools

Site Tools


nodejs_on_metaarray

This is an old revision of the document!


Setting up a simple Node.js Server

You can try Node.js by using your Port Allocation on the The MetaArray to run your own Node.js server. What follows is a bare-bones 'Hello, World' exmaple tailored for the metaarray:

  1. go to a project folder in your user folder, say <tt>~/projects/nodejstest</tt>
  2. use your favorite editor to open a new file called app.js
    • paste the following code into the file:
      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 = 'username.sdf.org';
           //const port = *replace this with your UID as port number, uncomment this line, then delete the line below*;
           const port = 8388;
      
           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}/`);
              });
  3. run the server with node app.js
  4. 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?300×300|browser showing 'Hello World, this is node'} }
  5. quit the server with ctl-c
nodejs_on_metaarray.1642727999.txt.gz · Last modified: 2022/01/21 01:19 by peteyboy