Answers for "nodejs express service"

53

express.js server

/* ====== create node.js server with express.js framework ====== */
// dependencies
const express = require("express");

const app = express();

app.get("/", (req, res) => {
   res.send("This is home page.");
});

app.post("/", (req, res) => {
   res.send("This is home page with post request.");
});

// PORT
const PORT = 3000;

app.listen(PORT, () => {
   console.log(`Server is running on PORT: ${PORT}`);
});


// ======== Instructions ========
// save this as index.js
// you have to download and install node.js on your machine
// open terminal or command prompt
// type node index.js
// find your server at http://localhost:3000
Posted by: Guest on January-13-2021
6

express server

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 February-28-2021
0

js express server

const http = require('http')
const express = require('express')

const app = express()
const server = http.Server(app)
app.set('port', 8888)
server.listen(8888)

app.get('/', (req, res) => {
  res.json({teste: true})
})
Posted by: Guest on January-30-2021
0

how to set up an express api nodejs

const express = require('express')

const app = express() 

app.get('/', (req, res, next) => {
	res.json({
      message: 'This is my JSON api'
    });
});

app.listen(your-port-here, () => {
	console.log(`listening on http://localhost:${the-port-goes-here}`)
});

/*
WombleWoo7547 @ https://github.com/WombleWoo7547 https://replit.com/@WombleWoo7547
*/
Posted by: Guest on May-27-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language