How to close a node.js program with express in vue? - node.js

I work with express and vue3 I have found multiple solutions but they all do not seem to work because of vue
I have something like this
<template>
<div>
<button v-on:click="exit"></button>
</div>
</template>
and I just want to close the application with this.
<script>
function exit() {
process.exit(1)
}
</script>

Related

Put pagination in page. nodejs mongodb ejs file

I've been stuck on this functionality for awhile. I've tried the frontend ways and backend as well. things I've tried doing are sending limited data from backend as response https://youtu.be/vP9fOEAlo74 this video was very close to solving my problem but i couldn't figure it out. I want a path or way to do this in best way possible.
frontend ejs file code:
<%- include("partials/header"); -%>
<% posts.forEach(function(post){ %>
<h2><%=post.title%></h2>
<p>
<%=post.content.substring(0, 440) + " ..."%>
<a class="styleAnchor" href="/posts/<%=post._id%>">Read More</a>
</p>
<% }) %>
<%- include("partials/footer"); -%>
backend code:
app.get("/blogs", function(req,res){
Post.find({}, function(err, posts){
res.render("blogs", {posts: posts});
});
});
the website is currently live on heroku app and data comes from mongodb atlas
feel free to visit to understand.
thank you for your time!

How to use ckeditor in nodejs application?

I am developing a crud application in nodejs using handlebars templating engine. Now I want to add editor like ckeditor or any similar kind of editor in my application.
CKEditior is a front-end plug-in that runs directly in the browser you use it like any other front-end js plugin here is an example
<div class="entry">
<script src="https://cdn.ckeditor.com/4.9.1/standard/ckeditor.js"></script>
<h1>{{title}}</h1>
<div class="body">
<textarea name="editor1"></textarea>
<script>
CKEDITOR.replace( 'editor1' );
</script>
{{body}}
</div>
</div>
in the json:
{
title: "My New Post",
body: "This is my first post!"
}
you can try it here: tryhandlebar

Captcha in MEAN js

I need to use Captcha in MEAN js login. I need the simplest possible way to make it work. I saw Visual Captcha but I'm not able to understand where should I use it in the MEAN js application.
I need an offline captcha solution on MEAN js app. I plan to deploy it on a raspberry pi.
You can use google recaptcha with external script file in mean stack page. There is a js code.
https://developers.google.com/recaptcha/docs/display#js_api
Just follow this.
<script type="text/javascript">
var onloadCallback = function() {
grecaptcha.render('html_element', {
'sitekey' : 'your_site_key'
});
};
</script> </head> <body>
<form action="?" method="POST">
<div id="html_element"></div>
<br>
<input type="submit" value="Submit">
</form>
<script src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit"
async defer>
</script> </body> ```

How can I serve mp3 file on node js?

I am building simple web app that if the user press button, it will make sound(mp3 file in the server side).
//html file
<script>
function playSound () {
document.getElementById('play').play();
}
</script>
<body>
<audio id='play', src='http://127.0.0.1:1337/', type='audio/mpeg'
<button onclick='playSound()' class='btn btn-danger btn-circle btn-lg'>
<i class='fa fa-5x fa-fire'>
</body>
//app.js
app.get('/music.mp3', function(req, res){
ms.pipe(req, res, "/music.mp3");
});
It works if I insert online source in audio attribute, but it does not serve my local server file. How can I fix this?
Thanks in advance!
To serve static files such as images, CSS files, and JavaScript files, audio, use the express.static built-in middleware function in Express.
app.use(express.static('public'));
I've already answered such type of question. See this answer

ReactDOM renderToStaticMarkup renders <noscript></noscript>

I have a universal app with React Router.
let html = ReactDOM.renderToStaticMarkup(
<Provider store={store}>
<RoutingContext {...renderProps} />
</Provider>
);
The above is my React markup.
When I view my page source I see:
<div id="app">
<noscript></noscript>
<div id="home">
<h2>Home</h2>
</div>
</div>
What is this noscript tag? Can I get rid of it?
You seem to have confused Redux Router with React Router in the question.
The fragment of code you are running is for React Router, so I’ll assume that’s what you’re using.
React renders <noscript> for components that returned null during rendering.
Could it be that in your route configuration, there is no component matching that particular route?
Or that your component returned null?
It is hard to say more without seeing the full source code.

Resources