What do you want to save?
Add Code snippet
New code examples
-
Javascript 2021-09-23 01:45:03
create server and connect to db and frontend
// create directory //npm init -y //npm i express --save //npm i mysql --save //create public directory //create server.js // <---- In the server js file ---> 'use strict'; const express = require('express'); const app = express(); app.use(expre... Add solution -
Javascript 2021-09-21 18:13:02
API requests return index.html in production
// use this after route not before route if (process.env.NODE_ENV === 'production') { app.use(express.static(resolve(process.cwd(), 'client/build'))) app.get('*', (req, res) => { res.sendFile(resolve(process.cwd(), 'client/build/index.html')) ... Add solution -
Javascript 2021-09-21 06:11:02
node app create
#1. server.js var express = require('express'); var app = express(); app.get('/', function (req, res) { res.status(200).send('Hello World!'); }); var port = process.env.PORT || 3000; var server = app.listen(port, function() { console.log('Express s... Add solution -
Javascript 2021-09-21 06:10:02
express server replit
const express = require('express'); const bodyParser = require('body-parser'); const app = express(); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: true })); app.use(express.static('public')); app.get('/', (req, res) => { r... Add solution -
Javascript 2021-09-18 10:59:03
nodejs response is html not json data
// use this after route not before route if (process.env.NODE_ENV === 'production') { app.use(express.static(resolve(process.cwd(), 'client/build'))) app.get('*', (req, res) => { res.sendFile(resolve(process.cwd(), 'client/build/index.html')) ... Add solution -
Javascript 2021-09-17 14:09:02
how to handle all error of all router in express
// development error handler // will print stacktrace if (app.get('env') === 'development') { app.use(function (err, req, res, next) { res.status(err.status || 500); res.render('error.ejs', { message: err.message, ... Add solution -
Javascript 2021-09-16 21:10:02
express js basic example
//to run : node filename.js 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}`)) /... Add solution