ejs

How to use sweetalert in nodejs?

那年仲夏 提交于 2020-06-28 08:21:10
问题 I have a nodejs code given with html code, I want to show a sweet alert on client side,after process a function in nodejs?. var express = require('express'); var router = express.Router(); const Swal = require('sweetalert2'); router.post('/add', function(req, res, next) { Swal('Hello world!'); }); <!DOCTYPE html> <html lang="pt_br"> <head> </head> <body> <h1 class="text-center title-1"> Cad </h1> <form action="/add" method="post"> <input type="submit" value="Save"/> </form> </body> </html>

EJS: pass a variable to the included file

南笙酒味 提交于 2020-06-25 04:44:07
问题 I'm using EJS as a part of my front-end dev stack. For example my normal index.ejs looks like that: <%- include parts/header.ejs %> <%- include parts/navigation.ejs %> <!-- HTML content: divs, spans, etc. --> <%- include parts/footer.ejs %> What I want is to pass somehow a variable with the include <%- include parts/footer.ejs? variable=value %> and want to read it in the included file, to conditionally show/hide some parts of the content. I can't find the way to do it. Is it possible with

Improve mongoose validation error handling

北城以北 提交于 2020-06-16 20:49:19
问题 I have the following schema with required validations: var mongoose = require("mongoose"); var validator = require("validator"); var userSchema = new mongoose.Schema( { email: { type: String, required: [true, "Email is a required field"], trim: true, lowercase: true, unique: true, validate(value) { if (!validator.isEmail(value)) { throw new Error("Please enter a valid E-mail!"); } }, }, password: { type: String, required: [true, "Password is a required field"], validate(value) { if (

Improve mongoose validation error handling

家住魔仙堡 提交于 2020-06-16 20:48:41
问题 I have the following schema with required validations: var mongoose = require("mongoose"); var validator = require("validator"); var userSchema = new mongoose.Schema( { email: { type: String, required: [true, "Email is a required field"], trim: true, lowercase: true, unique: true, validate(value) { if (!validator.isEmail(value)) { throw new Error("Please enter a valid E-mail!"); } }, }, password: { type: String, required: [true, "Password is a required field"], validate(value) { if (

How can I pass Express.js variables to MongoDB functions?

坚强是说给别人听的谎言 提交于 2020-05-29 06:24:31
问题 I am working on a blogging application (click the link to see the GitHub repo) with Express, EJS and MongoDB. I have made a simple pager for the posts. In the posts controller I have: exports.getPosts = async (req, res, next) => { const posts = await Post.find({}, (err, posts) => { const perPage = 10; const currPage = req.query.page ? parseInt(req.query.page) : 1; const postsCount = posts.length; const pageCount = Math.ceil(postsCount / perPage); const pageDecrement = currPage > 1 ? 1 : 0;

How to send each string object in an array as ajax post data

懵懂的女人 提交于 2020-05-17 07:46:11
问题 I have dynamically generated text boxes and each value has to be stored in a JSON array when posted. I pushed all the values to an array and when I post it, those values in an array are read as one object in a JSON array in my JavaScript server file. For a better understanding, here's my code snippet below: // my javascript server const express = require("express"); const MongoClient = require("mongodb").MongoClient; const app = express(); const {DB_URL} = require("./credentials"); const

How to send each string object in an array as ajax post data

匆匆过客 提交于 2020-05-17 07:46:07
问题 I have dynamically generated text boxes and each value has to be stored in a JSON array when posted. I pushed all the values to an array and when I post it, those values in an array are read as one object in a JSON array in my JavaScript server file. For a better understanding, here's my code snippet below: // my javascript server const express = require("express"); const MongoClient = require("mongodb").MongoClient; const app = express(); const {DB_URL} = require("./credentials"); const

NodeJS & EJS POST

£可爱£侵袭症+ 提交于 2020-05-16 04:34:52
问题 I'm using NodeJS/Express and EJS to create a form to an API route. When I try a POST request and call req.body.password & req.body.confirm , I get "undefined". index.js import http from 'http'; import express from 'express'; import bodyParser from 'body-parser'; import mongoose from 'mongoose'; import passport from 'passport'; const LocalStrategy = require('passport-local').Strategy; var flash = require('connect-flash'); import config from './config'; import routes from './routes'; let app =

how to use ejs lint in cli

て烟熏妆下的殇ゞ 提交于 2020-05-15 02:58:06
问题 I am using EJS as my view engine on a node and express setup. I want to use ejs-lint to help get the line for errors. I haven't use a linter before, but from reading through the documentation here: https://github.com/RyanZim/EJS-Lint I'm assuming you can just check errors on a specified file in command line like this: ejslint Are my assumptions right and what am I doing wrong? I've already installed using npm install ejs-lint --save-dev Also, if I plan to add ESlint to my project I'm guessing

Chart.js creating a line graph using dates

て烟熏妆下的殇ゞ 提交于 2020-05-10 07:43:16
问题 I can't seem to get Chart.js to work with dates. I have tried quite a few different methods: let examChart = document.getElementById("examChart").getContext("2d"); let examLineChart = new Chart(examChart, { type: "line", data: [ { t: new Date("2015-3-15 13:3"), y: 12 }, { t: new Date("2015-3-25 13:2"), y: 21 }, { t: new Date("2015-4-25 14:12"), y: 32 } ], options: { label: "placeholder" } }); And: let examChart = document.getElementById("examChart").getContext("2d"); let examLineChart = new