Skip to content

Instantly share code, notes, and snippets.

const mongoose = require('mongoose')
mongoose.connect('mongodb://localhost/<db name>')
et arrayOne=['1','2','1','2']
console.log(arrayOne)
// ['1','2','1','2']
let setOne= new Set(arrayOne)
for(elem of setOne){
console.log(elem)
}
git checkout <git-hash>
git checkout <branch-name>
git checkout master
git branch // lists all the branches
git branch <new-branch-name>
git merge <branch-name> // merges the current branch with the spesified branch
const express = require('express')
const app = express()
const path = require('path')
app.use(express.static('client/build'))
app.get('*', (req, res) => {
const filePath = path.join(__dirname, 'client', 'build', 'index.html')
res.sendFile(filePath)
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"
heroku login (Enter your Heroku credentials)
git init
git add .
git commit -m “initial commit”
heroku create (You should see two links after running this command. Copy the second one)
git remote add heroku PASTE THE LINK YOU JUST COPIED
git push heroku master
Once you run the last command Heroku will start to run some tests on your app. If everything goes right you should see a successful deploy message. Now you’re able to navigate to your app by running:
heroku open
1 . you need to create the views directory
2 . include this line of code : app.set('view engine', 'ejs');
// include partials
<% include ../partials/head %>
// loop over data
<h2>Loop</h2>
<ul>
const axios = require('axios')
// queryParams
axios.get(url, {
params:{
key: value
}
}
)
// output
// gnerate token function
const jwt = require('jsonwebtoken');
const jwtSecret = process.env.JWT_SECRET;
module.exports = (obj) => {
return jwt.sign(obj, jwtSecret, {
expiresIn: '1day',
});
};
// ==================
// With a JSON doc
Person.
find({
occupation: /host/,
'name.last': 'Ghost',
age: { $gt: 17, $lt: 66 },
likes: { $in: ['vaporizing', 'talking'] } // see if the value of likes included in ['vaporizing, 'talking'] array
// syntax {property: {$in: array...}}
}).
limit(10).