This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express') | |
const app = express() | |
// path is a built in module in Node | |
// It Helps get the specific path to the files | |
const path = require('path') | |
app.listen( 3000, () => { | |
console.log('App listening on port 3000') | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// GET method route | |
app.get('/', function (req, res) { | |
res.send('GET request to the homepage') | |
}) | |
// POST method route | |
app.post('/', function (req, res) { | |
res.send('POST request to the homepage') | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
node index.js | |
# This gets log to the terminal | |
App listening on port 3000 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const server = http.createServer( (req, res) => { | |
... | |
} ) | |
server.listen(3000) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Require Express Module | |
const express = require('express') | |
// Calls express function to start new Express app. | |
const app = express() | |
app.listen( 3000, () => { | |
console.log( 'App listening on port 3000' ) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
npm install express |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# It will ask you a bunch of questions, and then write a package.json for you. | |
npm init | |
# or generate an empty npm project without going through an interactive process. | |
npm init -y |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const http = require( 'http' ) | |
// import 'fs' a file system module which | |
// helps interact with files on our server | |
const fs = require('fs') | |
// The 'readFileSync' method from 'fs' | |
// reads the content of each file and returns it. | |
const homePage = fs.readFileSync('index.html') | |
const aboutPage = fs.readFileSync('about.html') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
touch index.html about.html contact.html 404.html |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const http = require( 'http' ) | |
const server = http.createServer( ( req, res ) => { | |
console.log( req.url ) | |
switch( req.url ) { | |
case '/': | |
res.end( 'The Homepage' ) |