Advertisement
metalx1000

NodeJS - Basic HTTP Webserver Setup

Feb 24th, 2015
630
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.72 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. browser="google-chrome"
  4. dir="node_webserver"
  5. mkdir $dir
  6. cd $dir
  7.  
  8. if [ ! -f "/usr/bin/nodejs" ]
  9. then
  10.   sudo apt-get install nodejs
  11. fi
  12.  
  13. npm install --save express@4.10.2
  14.  
  15. cat << EOF > server.js
  16. var app = require('express')();
  17. var http = require('http').Server(app);
  18.  
  19. app.get('/', function(req, res){
  20.   res.sendFile(__dirname + '/index.html');
  21. });
  22.  
  23. http.listen(3000, function(){
  24.   console.log('listening on *:3000');
  25. });
  26. EOF
  27.  
  28. cat << EOH > index.html
  29. <!doctype html>
  30. <html>
  31.   <head>
  32.     <title>Welcome</title>
  33.   </head>
  34.  
  35.   <body>
  36.     <h1>Hellow World</h1>
  37.     <a href="http://filmsbykris.com">Learn More</a>
  38.   </body>
  39. </html>
  40. EOH
  41.  
  42. $browser "http://127.0.0.1:3000" &
  43. nodejs server.js
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement