Skip to content

Instantly share code, notes, and snippets.

@tphdev
Created June 14, 2018 16:14
Show Gist options
  • Save tphdev/364fe51052eff02a0add8ebcc76f42dc to your computer and use it in GitHub Desktop.
Save tphdev/364fe51052eff02a0add8ebcc76f42dc to your computer and use it in GitHub Desktop.
node-demo-notes

Slides

Code

setup
npm init
npm install --save express

package.json

...
  "scripts":{
    "start" : "node index.js "
  }
...
index.js
const express = require('express')
const fs = require('fs')

const app = express()

const PORT = process.env.NODE_ENV ||  3000  
const HOST = '0.0.0.0'

app.use( express.static( __dirname + '/public') );

app.use( (req,res) => {
  fs.readFile( __dirname + '/public/404.html', 'utf-8', (err, fileContents)=>{
      res.send( fileContents )
  })
});

app.listen( PORT , HOST, () => console.log('Example app listening on port 3000!'))

Misc

npm install -g now
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment