- Running JS in a command terminal
- Structuring an NPM package
- Node console.log()
- Scripting and dependencies
- const
- Arrow functions
Hello, world.
$ node -e 'console.log("Hello, world.")
'Hello, world.
Hello, world.
const hello = "Hello, world."
console.log(hello)
package.json
{
"name": "my-own-private-web-server",
"version": "0.0.1",
"description": "This package contains a very simple web server that takes one argument for port and then serves index.html in the www directory.",
"main": "server.js",
"scripts": {
"test": "node server.js",
"start": "node server.js"
},
"author": "John D. Martin III",
"license": "GPL-3.0-or-later",
"dependencies": {
"minimist": "^1.2.5"
}
}
const
const http = require('http')
const fs = require('fs')
const args = require('minimist')(process.argv.slice(2))
Arrow functions
( params ) => { statements }
const name = ( params ) => { statements }
Arrow functions
(req, res) => {
res.statusCode = 200
res.setHeader('Content-Type', 'text/html')
res.end(data)
}
Arrow functions
const server = http.createServer((req, res) => {
res.statusCode = 200
res.setHeader('Content-Type', 'text/html')
res.end(data)
})