What do you want to save?
Add Code snippet
New code examples
-
Javascript 2022-01-23 01:25:57
express hello world
const http = require('http'); const hostname = '127.0.0.1'; const port = 3000; const server = http.createServer((req, res) => { res.statusCode = 200; res.setHeader('Content-Type', 'text/plain'); res.end('Hello World'); }); server.listen(port, ... Add solution -
Javascript 2022-01-22 15:31:24
express set response code
res.status(400); res.send('None shall pass'); Add solution -
Javascript 2022-01-22 12:15:02
mern stack delete
//MERN STACK DELETE //Route import { deletePost } from "../controllers/posts.js" router.delete("./:id", deletePost) //Controller export const deletePost = async (req, res) => { const { id } = req.params; if (!mongoose.Types.O... Add solution -
Javascript 2021-11-14 05:26:11
Axios Req with Auth Token
const res = await axios.get('https://httpbin.org/basic-auth/foo/bar', { // Axios looks for the `auth` option, and, if it is set, formats a // basic auth header for you automatically. auth: { username: 'foo', password: 'bar' } }); res.statu... Add solution -
Javascript 2021-11-13 20:56:10
create server with express js
// npm init // npm i express const express = require('express'); const server = express(); const PORT = 3000; // Body parser server.use(express.json()); // Homme page server.get('/', (req, res) => { return res.send("<h1 style='text-align:... Add solution -
Javascript 2021-11-09 17:32:08
filter a query string with comparison operator
//if need to find ratings greater then 3 //The query string may be: //127.0.0.1:8000/api/v1/posts?ratings[gt]=3 //if we check the req.query //{ ratings: { gt: '3' } } exports.getPosts = async (req, res) => { try { const queryObj = { ...req.query ... Add solution