Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

setup app files in node js

const express = require ('express')
const path = require('path')
const app = express()

///npm install body-paraser

const bodypraser = require('body-parser'); 
app.use(bodypraser.json())
app.use(bodypraser.urlencoded({extended:true}))


//setup static and middleware
app.use(express.static('./public'))

app.get('/', (req, res) =>{
    console.log('user hit the resource')
    res.sendFile(path.resolve(__dirname, '../../02-express-tutorial/navbar-app/index.html'))
})

app.get('/contact', (req, res) => {
    console.log('user is on contact page')

    res.send('Contact Page')
})
app.get('*', (req, res) =>{
    res.status(404).send("<h1> Resource not found </h1>")
})


app.listen(5000, () => {
    console.log('server is listing on port 5000....');
})
 
PREVIOUS NEXT
Tagged: #setup #app #files #node #js
ADD COMMENT
Topic
Name
1+1 =