# Installing nodejs on FOX D27

<abstract>
Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine. 
Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient. 		
</abstract>

Nodejs version 18.13.0 is already installed on the MicroSD image available on this repository:

* @article='download_foxd27'

## Example of basic web server 

Save this example code in a file called __webserver.js__:

	const http = require('http');
	
	const hostname = '0.0.0.0';
	const port = 3000;
	
	const server = http.createServer((req, res) => {
	  res.statusCode = 200;
	  res.setHeader('Content-Type', 'text/plain');
	  res.end('Hello World\n');
	});
	
	server.listen(port, hostname, () => {
	  console.log(`Server running at http://${hostname}:${port}/`);
	});

Then run it:

	node webserver.js

Open the web url __http://acme_board_ip_address:3000__ on a browser on your PC to see the web server message generated by this 
example.

## Install Express JS

	npm install express
	
Express example:

	const express = require('express')
	const app = express()
	
	app.get('/', (req, res) => {
	  res.send('Hello World!')
	})
	
	app.listen(
	        3000, '0.0.0.0',
	        () => console.log(`Server listening on port 3000.`)
	);



