mean-stack

Getting error suddenly in Angular Error: NodeInjector: NOT_FOUND [ControlContainer]

淺唱寂寞╮ 提交于 2020-06-12 04:29:42
问题 core.js:5873 ERROR Error: NodeInjector: NOT_FOUND [ControlContainer]. Sometime when i restart the project it runs perfectly. there are only changes in app.component.html : <div class="container"> <div class="row"> <div class="col-md-4"> <form action=""> <div class="form-group"> <label for="">Username</label> <input type="text" name="username" class="form-control" /> </div> <div class="form-group"> <label>Password</label> <input type="password" class="form-control"> </div> <div class="form

How do I hash a string using JavaScript with sha512 algorithm

…衆ロ難τιáo~ 提交于 2020-06-01 07:22:26
问题 I've tried using sha512 from NPM but it keeps hashing the wrong thing i.e I am supposed to get a string but it keeps returning object. So in PHP I know I can perform the task $hash = hash("sha512","my string for hashing"); How do I perform this task on nodejs JavaScript 回答1: If you are using Node: > crypto.createHash('sha512').update('my string for hashing').digest('hex');

Express.js blogging application bug: filtering posts by category throws “Cast to ObjectId failed” failed error

六眼飞鱼酱① 提交于 2020-05-30 10:23:06
问题 I am working on a blogging application (click the link to see the GitHub repo) with Express, EJS and MongoDB. I have Posts that are grouped into Categories , each in its own collection. I run into a problem trying to filter posts by category. To obtain the post by category url, I turn the category name into a slug and use it this way: Posted in <a href="/<%= post.category.cat_name.replace(/\s+/g, '-').toLowerCase(); %>"><%= post.category.cat_name %></a> In the public routes file I have: const

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 do I count all the documents in a collection and use the cont in a controller, with MongoDB and Express.js?

大憨熊 提交于 2020-05-17 07:45:26
问题 I am working on a blogging application (click the link to see the GitHub repo) with Express, EJS and MongoDB. Trying to paginate the posts I did the following, in the controller: exports.getPosts = (req, res, next) => { const perPage = 5; const currPage = req.query.page ? parseInt(req.query.page) : 1; let postsCount = 0; const posts = Post.find({}, (err, posts) => { postsCount = posts.length; let pageDecrement = currPage > 1 ? 1 : 0; let pageIncrement = postsCount >= perPage ? 1 : 0; if (err)

Send update notification to particular users using socket.io

你离开我真会死。 提交于 2020-05-09 18:55:54
问题 Following is the code on front end, where storeSelUserId contains user_id to send the message- FYI - Node Version 1.1.0 // Socket Notification var socket = io('http://localhost:6868'); socket.on('connection', function (data) { socket.emit('send notification', { sent_to: storeSelUserId }); }); Following is the server code in routes file - var clients = {}; io.on('connection', function (socket) { socket.emit('connection', "Connection Created."); socket.on('send notification', function (sent_to)

Express.js application bug: form filed values do not persist

喜夏-厌秋 提交于 2020-04-11 02:02:31
问题 I am working on a blogging application (click the link to see the GitHub repo) with Express, EJS and MongoDB. There is an "Add New Post" form of course, with an addPost() method in the controller; exports.addPost = (req, res, next) => { const errors = validationResult(req); const post = new Post(); post.title = req.body.title; post.short_description = req.body.excerpt post.full_text = req.body.body; console.log(post); if (!errors.isEmpty()) { req.flash('danger', errors.array()); req.session

Express.js application bug: delete post route is not found

廉价感情. 提交于 2020-03-04 18:18:13
问题 I am working on a blogging application (click the link to see the GitHub repo) with Express, EJS and MongoDB. I have been unable to delete a post via AJAX. In my Dashboard routes file ( routes\admin\dashboard.js ) I have: // Delete Post router.delete('/post/delete/:id', dashboardController.deletePost); In my Dashboard controller: exports.deletePost = (req, res, next) => { const postId = req.params.id; posts.findByIdAndRemove(postId, function(err){ if (err) { console.log('Error: ', err); } res

Unable to connect to Mongodb.atlas cluster using MEAN stack

混江龙づ霸主 提交于 2020-02-25 08:04:27
问题 Having issues connecting to my server using the MEAN stack. I had no problems connecting until today and have not made code changes since so I am baffled on why all a sudden I am not able to connect. Connection: mongoose.connect("mongodb+srv://theller5567:" + process.env.MONGO_ATLAS_PW + "@cluster0-efzkv.mongodb.net/node-angular", { useNewUrlParser: true }) .then(() => { console.log("Connected to database!"); }) .catch((error) => { console.log("Connection failed!", error); }); Response:

Grunt Livereload not showing HTML changes

僤鯓⒐⒋嵵緔 提交于 2020-01-24 23:59:05
问题 On my MEAN stack application, I'm trying make changes to the HTML view files and see those changes as I make them using Grunt's livereload. Grunt's livereload is working fine in the sense that it detects changes in my HTML files and refreshes the page during development. However, the actual changes are not reflecting on the page. If I push the files up the server, and reload the publicly available site, the changes are there. But I still can't see the changes while I'm developing. I'm 99%