What do you want to save?
Add Code snippet
New code examples
-
Javascript 2021-11-15 18:43:10
set proxy to use nodejs in angular
// in NodeJS (3000 port) make: app.get('/api/user', (req, res) => { res.json({}); }); // in Angular (4200 port): // make call async ngOnInit(): Promise<void> { let result = await this.http.get("http://127.0.0.1:4200/api/user").to... Add solution -
Javascript 2021-11-12 02:10:11
what is the meanof using next in nodejs
/* Some people always write return next() is to ensure that the execution stops after triggering the callback. If you don't do it, you risk triggering the callback a second time later, which usually has devastating results. */ app.get('/users/:id?', fu... Add solution -
Javascript 2021-11-11 18:47:19
how to use of socket io on a route in nodejs
//Using Express 4, in your app.js file you can use app.set('socketio', io); //then in your router you can access it like this router.post('/getRides', function(req, res, next) { var io = req.app.get('socketio'); io.to(//socket.id//).emit("m... Add solution -
Javascript 2021-11-11 18:44:10
node js express
const express = require('express'); const app = express(); const PORT = process.env.PORT || 3000; app.get('/', (req, res) => { res.send('<h1>Some HTML</h1>'); res.send('<p>Even more HTML</p>'); }); app.listen(PORT, () =>... Add solution -
Other 2021-11-11 00:28:14
ejs jwt authentication
const cookieParser = require('cookie-parser') const withAuthUserId = [ cookieParser(), (req, res, next) => { const claims = jsonwebtoken.verify(req.cookies['jwt'], jwtKey) req['authUserId'] = claims['sub'] next() } ] app.get('/api/a... Add solution -
Javascript 2021-11-10 22:11:12
show data of mongoose in html page using ejs
app.get('/profileface', isLoggedIn, function(req, res) { // mongoose operations are asynchronous, so you need to wait PracticeModel.find({}, function(err, data) { // note that data is an array of objects, not a single object! res.... Add solution -
Javascript 2021-11-09 17:09:08
express signed cookies
var express = require('express'); var cookieParser = require('cookie-parser'); var app = express(); app.use(cookieParser('YOUR-SECRET-SALT')); app.get('/', (req, res, next) => { res.cookie('name', 'value', { signed: true }); res.send('Success'); ... Add solution