Advertisement
metalx1000

Setup a basic nodeJS server on Debian

Feb 24th, 2015
539
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.84 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. browser="google-chrome"
  4.  
  5. mkdir node_server
  6. cd node_server
  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. echo """
  16. var express = require('express')
  17. var app = express()
  18.  
  19. app.get('/', function (req, res) {
  20.  res.send('<h1>Hello World!</h1>')
  21.  console.log("Someone Connected and I said Hello!!!");
  22. })
  23.  
  24. app.get('/dir', function (req, res) {
  25.  var exec = require('child_process').exec;
  26.  exec('find /usr', function (error, stdout, stderr) {
  27.    // output is in stdout
  28.    res.send(stdout)
  29.  });
  30.  
  31. })
  32.  
  33. var server = app.listen(3000, function () {
  34.  
  35.  var host = server.address().address
  36.  var port = server.address().port
  37.  
  38.  console.log('Example app listening at http://%s:%s', host, port)
  39.  
  40. })
  41. """ > server.js
  42.  
  43. $browser "http://127.0.0.1:3000"
  44. nodejs server.js
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement