Answers for "express js docs"

5

nodejs express api

const express = require('express')
const app = express()
const port = 3000

app.get('/', (req, res) => {
  res.send('Hello World!')
})

app.listen(port, () => {
  console.log(`Example app listening at http://localhost:${port}`)
})
Posted by: Guest on April-15-2021
4

node.js express

const express = require('express')
const app = express()
const port = 3000

app.get('/', (req, res) => res.send('Hello World!'))

app.listen(port, () => console.log(`Example app listening at http://localhost:${port}`))
Posted by: Guest on April-01-2020
14

node js express

basic server

const express =require('express');
const app = express();
const PORT = 5000;


app.get('/',(req,res)=>{
   res.json({message: 'Welcome to the backend'})
})


app.listen(PORT ,()=>console.log(`Connected to ${PORT}`)
Posted by: Guest on April-02-2020
5

express redirect

res.redirect('/foo/bar')
res.redirect('http://example.com')
res.redirect(301, 'http://example.com')
res.redirect('../login')
Posted by: Guest on December-13-2019
3

node js express

// node js -> express -> basic example: static folder, 404 page

const express = require('express');
const path = require('path');
const PORT = process.env.PORT || 5000;

const app = express();

function error404(req, res) {
  res.status(404);

  if (req.accepts('html')) {
    res.sendFile(path.join(__dirname, 'public/errors/404.html'));
    return;
  }

  if (req.accepts('json')) {
    res.send({
      status: 404,
      error: 'Not found'
    });
    return;
  }
  
  res.type('txt').send('404 - Not found');
}

app
  .use(express.static(path.join(__dirname, 'public')))
  .use(error404)
  .listen(PORT, () => console.log(`Listening on ${ PORT }`));
Posted by: Guest on June-07-2020
7

express js

Express is a minimal and flexible Node.js web application framework
that provides a robust set of features for web and mobile
applications.
Posted by: Guest on April-14-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language