Skip to content

Instantly share code, notes, and snippets.

View elpuas's full-sized avatar
💻
coding

Alfredo Navas-Fernandini elpuas

💻
coding
View GitHub Profile
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')
})
// 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')
})
node index.js
# This gets log to the terminal
App listening on port 3000
const server = http.createServer( (req, res) => {
...
} )
server.listen(3000)
// 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' )
})
npm install express
@elpuas
elpuas / .bash
Last active April 6, 2021 21:23
# 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
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')
touch index.html about.html contact.html 404.html
const http = require( 'http' )
const server = http.createServer( ( req, res ) => {
console.log( req.url )
switch( req.url ) {
case '/':
res.end( 'The Homepage' )