Indentation error while executing app.js code using node.js, express.js and socket.io npm - node.js

I am newbie in node.js, express.js framework and socket.io please help me.
When i execute below code using node app.js command in ubuntu terminal. Its giving indentation error:
oneadmin#openflow1:~/Desktop/test-projects/nodejs/Datasift-Interaction-Counter-master$ node app.js
Express server listening on port 1337 in development mode
Warning: missing space before text for line 33 of jade file "/home/oneadmin/Desktop/test-projects/nodejs/Datasift-Interaction-Counter-master/views/layout.jade"
Error: unexpected token "indent"
at Parser.parseExpr (/home/oneadmin/Desktop/test-projects/nodejs/Datasift-Interaction-Counter-master/node_modules/jade/lib/parser.js:229:15)
at Parser.block (/home/oneadmin/Desktop/test-projects/nodejs/Datasift-Interaction-Counter-master/node_modules/jade/lib/parser.js:689:25)
at Parser.tag (/home/oneadmin/Desktop/test-projects/nodejs/Datasift-Interaction-Counter-master/node_modules/jade/lib/parser.js:800:26)
at Parser.parseTag (/home/oneadmin/Desktop/test-projects/nodejs/Datasift-Interaction-Counter-master/node_modules/jade/lib/parser.js:719:17)
at Parser.parseExpr (/home/oneadmin/Desktop/test-projects/nodejs/Datasift-Interaction-Counter-master/node_modules/jade/lib/parser.js:188:21)
at Parser.block (/home/oneadmin/Desktop/test-projects/nodejs/Datasift-Interaction-Counter-master/node_modules/jade/lib/parser.js:689:25)
at Parser.tag (/home/oneadmin/Desktop/test-projects/nodejs/Datasift-Interaction-Counter-master/node_modules/jade/lib/parser.js:800:26)
at Parser.parseTag (/home/oneadmin/Desktop/test-projects/nodejs/Datasift-Interaction-Counter-master/node_modules/jade/lib/parser.js:719:17)
at Parser.parseExpr (/home/oneadmin/Desktop/test-projects/nodejs/Datasift-Interaction-Counter-master/node_modules/jade/lib/parser.js:188:21)
at Parser.block (/home/oneadmin/Desktop/test-projects/nodejs/Datasift-Interaction-Counter-master/node_modules/jade/lib/parser.js:689:25)
app.js code following:
doctype html
html(lang='en')
head
meta(charset='utf-8')
//
Set the viewport width to device width for mobile
meta(name='viewport', content='width=device-width')
title DataSift :: Interaction Analyzer
//
Included CSS Files
link(rel='stylesheet', href='stylesheets/foundation.css')
link(rel='stylesheet', href='stylesheets/app.css')
//if lt IE 9
link(rel='stylesheet', href='stylesheets/ie.css')
//
IE Fix for HTML5 Tags
//if lt IE 9
script(src='http://html5shiv.googlecode.com/svn/trunk/html5.js')
//
Included JS Files
script(type='text/javascript', src='/socket.io/socket.io.js')
script(type='text/javascript', src='http://code.jquery.com/jquery-latest.js')
script(type='text/javascript', src='javascripts/modernizr.foundation.js')
script(type='text/javascript', src='javascripts/foundation.js')
script(type='text/javascript', src='javascripts/d3.js')
script(type='text/javascript', src='javascripts/d3.geom.js')
script(type='text/javascript', src='javascripts/d3.layout.js')
script(type='text/javascript', src='javascripts/d3.time.js')
script(type='text/javascript', src='javascripts/d3.word.cloud.js')
script(type='text/javascript', src='/javascripts/app.js')
script(type='text/javascript', src='/javascripts/graph-ic.js')
script
$(document).ready(function() {
$('#go').click(function() {
$.ajax({
type : 'POST',
url : '/submit',
data : $('#stream_creds').serialize(),
success : function(response) {
$('#ContactForm').find('.form_result').html(response);
}
});
});
});
body
//
container
.container
.row
.eight.columns
img(src='images/dslogo.png')
h4.subheader Interaction Volume
.panel
h4
| Total interactions:
span#countTotal
.four.columns
.panel.hide-on-phones
form#stream_creds.nice
input.input-text(type='text', placeholder='User Name', name='username')
input.input-text(type='text', placeholder='API Key', name='apikey')
input.input-text(type='text', placeholder='Stream ID', name='streamid')
p
a#go.nice.radius.blue.button.mobile.src-download(href='#') Subscribe
.row
.one.columns
.ten.columns
ul.nice.tabs-content
li#nice1Tab.active
#interactions
style(type='text/css')
svg {
font: 10px sans-serif;
}
.line {
fill: none;
stroke: #333;
stroke-width: 1.5px;
}
.axis path, .axis line {
fill: none;
stroke: #333;
shape-rendering: crispEdges;
}
.text {
fill: #333;
}
.data-line {
stroke: #F00;
stroke-width: 2;
fill: none;
stroke-dasharray: 0;
}
//
container
project link that i was trying to implementing in my local system ubuntu
http://www.benh.co.uk/datasift/visualising-a-datasift-feed-with-node-and-d3/
source code in git
https://github.com/haganbt/Datasift-Interaction-Counter
how to solve indentation error or how to execute successfully with fresh installation. Please let me help to solve this error

You need to add a dot . after your script/style tags if you're using inline javascript and CSS.
doctype html
html(lang='en')
head
meta(charset='utf-8')
//
Set the viewport width to device width for mobile
meta(name='viewport', content='width=device-width')
title DataSift :: Interaction Analyzer
//
Included CSS Files
link(rel='stylesheet', href='stylesheets/foundation.css')
link(rel='stylesheet', href='stylesheets/app.css')
//if lt IE 9
link(rel='stylesheet', href='stylesheets/ie.css')
//
IE Fix for HTML5 Tags
//if lt IE 9
script(src='http://html5shiv.googlecode.com/svn/trunk/html5.js')
//
Included JS Files
script(type='text/javascript', src='/socket.io/socket.io.js')
script(type='text/javascript', src='http://code.jquery.com/jquery-latest.js')
script(type='text/javascript', src='javascripts/modernizr.foundation.js')
script(type='text/javascript', src='javascripts/foundation.js')
script(type='text/javascript', src='javascripts/d3.js')
script(type='text/javascript', src='javascripts/d3.geom.js')
script(type='text/javascript', src='javascripts/d3.layout.js')
script(type='text/javascript', src='javascripts/d3.time.js')
script(type='text/javascript', src='javascripts/d3.word.cloud.js')
script(type='text/javascript', src='/javascripts/app.js')
script(type='text/javascript', src='/javascripts/graph-ic.js')
script.
$(document).ready(function() {
$('#go').click(function() {
$.ajax({
type : 'POST',
url : '/submit',
data : $('#stream_creds').serialize(),
success : function(response) {
$('#ContactForm').find('.form_result').html(response);
}
});
});
});
body
//
container
.container
.row
.eight.columns
img(src='images/dslogo.png')
h4.subheader Interaction Volume
.panel
h4
| Total interactions:
span#countTotal
.four.columns
.panel.hide-on-phones
form#stream_creds.nice
input.input-text(type='text', placeholder='User Name', name='username')
input.input-text(type='text', placeholder='API Key', name='apikey')
input.input-text(type='text', placeholder='Stream ID', name='streamid')
p
a#go.nice.radius.blue.button.mobile.src-download(href='#') Subscribe
.row
.one.columns
.ten.columns
ul.nice.tabs-content
li#nice1Tab.active
#interactions
style(type='text/css').
svg {
font: 10px sans-serif;
}
.line {
fill: none;
stroke: #333;
stroke-width: 1.5px;
}
.axis path, .axis line {
fill: none;
stroke: #333;
shape-rendering: crispEdges;
}
.text {
fill: #333;
}
.data-line {
stroke: #F00;
stroke-width: 2;
fill: none;
stroke-dasharray: 0;
}
//
container

html(lang='en')
<![endif]
head
meta(charset='utf-8')
//
Set the viewport width to device width for mobile
meta(name='viewport', content='width=device-width')
title DataSift :: Interaction Analyzer
//
Included CSS Files
link(rel='stylesheet', href='stylesheets/foundation.css')
link(rel='stylesheet', href='stylesheets/app.css')
//if lt IE 9
link(rel='stylesheet', href='stylesheets/ie.css')
//
IE Fix for HTML5 Tags
//if lt IE 9
script(src='http://html5shiv.googlecode.com/svn/trunk/html5.js')
//
Included JS Files
script(type='text/javascript', src='/socket.io/socket.io.js')
script(type='text/javascript', src='http://code.jquery.com/jquery-latest.js')
script(type='text/javascript', src='javascripts/modernizr.foundation.js')
script(type='text/javascript', src='javascripts/foundation.js')
script(type='text/javascript', src='javascripts/d3.js')
script(type='text/javascript', src='javascripts/d3.geom.js')
script(type='text/javascript', src='javascripts/d3.layout.js')
script(type='text/javascript', src='javascripts/d3.time.js')
script(type='text/javascript', src='javascripts/d3.word.cloud.js')
script(type='text/javascript', src='/javascripts/app.js')
script(type='text/javascript', src='/javascripts/graph-ic.js')
script.
$(document).ready(function() {
$('#go').click(function() {
$.ajax({
type : 'POST',
url : '/submit',
data : $('#stream_creds').serialize(),
success : function(response) {
$('#ContactForm').find('.form_result').html(response);
}
});
});
});
body
//
container
.container
.row
.eight.columns
img(src='images/dslogo.png')
h4.subheader Interaction Volume
.panel
h4
| Total interactions:
span#countTotal
.four.columns
.panel.hide-on-phones
form#stream_creds.nice
input.input-text(type='text', placeholder='User Name', name='username')
input.input-text(type='text', placeholder='API Key', name='apikey')
input.input-text(type='text', placeholder='Stream ID', name='streamid')
p
a#go.nice.radius.blue.button.mobile.src-download(href='#') Subscribe
.row
.one.columns
.ten.columns
ul.nice.tabs-content
li#nice1Tab.active
#interactions
style(type='text/css')
svg {
font: 10px sans-serif;
}
.line {
fill: none;
stroke: #333;
stroke-width: 1.5px;
}
.axis path, .axis line {
fill: none;
stroke: #333;
shape-rendering: crispEdges;
}
.text {
fill: #333;
}
.data-line {
stroke: #F00;
stroke-width: 2;
fill: none;
stroke-dasharray: 0;
}
//
container

Related

Replacing Font Awesome in heading with local SVG

I'm using this snippet for adding a Font Awesome icon in front of H1 headings:
h1:before {
content: "\f192 ";
font-family: "FontAwesome";
color: blueviolet;
}
How to adapt it for using a locally served (on site's server) SVG icon instead?
(that is uploaded in WP Media Library and using SVG Support plugin)
If your icon needs to remain a separate file, you can set it as a background image.
h1:before {
display: inline-block;
background-image: url(resources/icon.svg)
}
Otherwise you can embed your icon as a data url.
h1:before {
display: inline-block;
background-image: url(data:image/svg+xml,...etc...)
}
Update
Working example:
h1:before {
content: " ";
display: inline-block;
width: 0.7em;
height: 0.7em;
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10'%3E%3Ccircle cx='5' cy='5' r='5'/%3E%3C/svg%3E");
background-size: contain;
background-repeat: no-repeat;
}
<h1>This is a title</h1>

Font Awesome 4.7 to 5 broken?

Be forgiving, I am new to css let alone fontawesome :-)
I wanted to have a nice set of rating stars 0-5 and I managed it sort of using 4.7
https://jsfiddle.net/BoxRec/p3zgeLbt/36
content: "\f005\f006\f006\f006\f006";
However I needed half stars to complete the look and this required going to fontawesome 5
https://jsfiddle.net/BoxRec/p3zgeLbt/38
content: "\f005\f089\f006\f006\f006";
So I used the 5 library and now I now have the half star \f5c0 but the full star \f005 renders the same as the empty star \f006
https://jsfiddle.net/BoxRec/p3zgeLbt/46/
content: "\f005\f5c0\f006\f006\f006";
If you go to the cheatsheet, you can see that \f006 is gone in FontAwesome 5. I would (not a css guy) just use before and after tags to make the same effect. Regular vs solid is just changing the font weight.
note that I changed the font-family to 'Font Awesome\ 5 Free'
i.star {
font-family: 'Font Awesome\ 5 Free';
font-size: 16px;
color: #ffaa00;
font-style: normal;
}
i.s1::before {
content: "\f005";
font-weight: 900;
}
i.s1::after {
content: "\f005\f005\f005\f005";
font-weight: 200;
}
i.s1-5::before {
content: "\f005\f5c0";
font-weight: 900;
}
i.s1-5::after {
content: "\f005\f005\f005";
font-weight: 200;
}
Had to add this to the HTML:
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.12.0/css/all.css">

NodeJS with Puppeteer: how to set the margins of each pages (or scale all of them to fit the magins)?

I tried to just use below setting but turn out the header and footer positions will be changed. Please advise.
await page.pdf({
path: FILENAME,
format: 'A4',
margin: {
top: "0px",
right: "0px",
bottom: "0px",
left: "0px"
},
printBackground: true // required for photos otherwise blank
});
try preferCSSPageSize: true in page.pdf options.
This allows you to specify the margin's for page in the CSS and it will take priority.
**place CSS **
<style>
#page
{
size: A4 portrait;
margin:0;
}
</style>

Zingchart real time data feed

I have this Zingchart(gauge type) which displays random numbers from 1 to 100 using JS. I need to achieve the same via PHP. How can I do this? What are the necessary changes that needs to be done?
window.feed = function(callback) {
var tick = {};
tick.plot0 = Math.ceil(Math.random() * 100);
callback(JSON.stringify(tick));
refresh:{
type:"feed",
transport:"js",
url:"feed()",
interval:1000,
resetTimeout:1000
},
The necessary changes to work in php would be to set up a endpoint to hit. If you did something like:
window.feed = function(callback) {
var tick = {};
tick.plot0 = Math.ceil(Math.random() * <?php $phpValue ?>);
callback(JSON.stringify(tick));
The variable $phpValue would not work for a Javascript feed function because that value would printed only ONE time as the server compiles the php ONCE.
What to do then?
You want to add a proper url endpoint which returns the tick format. That would look something like this:
refresh: {
type: 'feed',
transport: 'http',
url: 'https://us-central1-zingchart-com.cloudfunctions.net/public_http_feed?min=0&max=50&plots=2',
interval: 200
}
Where the url returns the following data structure:
[{
plot0: 3,
plot1: 18,
'scale-x': "13:33:48" // optional scale-x argument to produce [x,y] plotting
}]
You can read more on the http docs.
Solution
Demo here
// define top level feed control functions
function clearGraph() {
zingchart.exec('myChart', 'clearfeed')
}
function startGraph() {
zingchart.exec('myChart', 'startfeed');
}
function stopGraph() {
zingchart.exec('myChart', 'stopfeed');
}
// window.onload event for Javascript to run after HTML
// because this Javascript is injected into the document head
window.addEventListener('load', () => {
// Javascript code to execute after DOM content
//clear start stop click events
document.getElementById('clear').addEventListener('click', clearGraph);
document.getElementById('start').addEventListener('click', startGraph);
document.getElementById('stop').addEventListener('click', stopGraph);
// full ZingChart schema can be found here:
// https://www.zingchart.com/docs/api/json-configuration/
const myConfig = {
//chart styling
type: 'line',
globals: {
fontFamily: 'Roboto',
},
backgroundColor: '#fff',
title: {
backgroundColor: '#1565C0',
text: 'Real-Time Line Chart',
color: '#fff',
height: '30x',
},
plotarea: {
marginTop: '80px'
},
crosshairX: {
lineWidth: 4,
lineStyle: 'dashed',
lineColor: '#424242',
marker : {
visible : true,
size : 9
},
plotLabel: {
backgroundColor: '#fff',
borderColor: '#e3e3e3',
borderRadius:5,
padding:15,
fontSize: 15,
shadow : true,
shadowAlpha : 0.2,
shadowBlur : 5,
shadowDistance : 4,
},
scaleLabel: {
backgroundColor: '#424242',
padding:5
}
},
scaleY: {
guide: {
visible: false
},
values: '0:100:25'
},
tooltip: {
visible: false
},
//real-time feed
refresh: {
type: 'feed',
transport: 'http',
url: 'https://us-central1-zingchart-com.cloudfunctions.net/public_http_feed?min=0&max=50&plots=1',
interval: 500,
},
plot: {
shadow: 1,
shadowColor: '#eee',
shadowDistance: '10px',
lineWidth:5,
hoverState: {visible: false},
marker:{ visible: false},
aspect:'spline'
},
series: [{
values: [],
lineColor: '#2196F3',
text: 'Blue Line'
},{
values: [],
lineColor: '#ff9800',
text: 'Orange Line'
}]
};
// render chart with width and height to
// fill the parent container CSS dimensions
zingchart.render({
id: 'myChart',
data: myConfig,
height: '100%',
width: '100%',
});
});
html, body {
height:100%;
width:100%;
margin:0;
padding:0;
}
#myChart {
margin: 0 auto;
height: 380px;
width: 98%;
box-shadow: 5px 5px 5px #eee;
background-color: #fff;
border: 1px solid #eee;
display: flex;
flex-flow: column wrap;
}
.controls--container {
display: flex;
align-items: center;
justify-content: center;
}
.controls--container button {
margin: 40px;
padding: 15px;
background-color: #FF4081;
border: none;
color: #fff;
box-shadow: 5px 5px 5px #eee;
font-size: 16px;
font-family: Roboto;
cursor: pointer;
transition: .1s;
}
.controls--container button:hover {
opacity: .9;
}
/*button movement*/
.controls--container button:active {
border-width: 0 0 2px 0;
transform: translateY(8px);
opacity: 0.9;
}
.zc-ref { display:none; }
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>ZingGrid: Blank Grid</title>
<script src="https://cdn.zingchart.com/zingchart.min.js"></script>
</head>
<body>
<!-- CHART CONTAINER -->
<div id="myChart">
<a class="zc-ref" href="https://www.zingchart.com">Powered by ZingChart</a>
</div>
<div class="controls--container">
<button id="clear">Clear</button>
<button id="stop">Stop</button>
<button id="start">Start</button>
</div>
</body>
</html>

Injecting remote iframe with Chrome extension

For the life of me, I cannot get my Chrome extension to display an iframe with a remote URL.
I see the following message in the console -
Refused to frame 'https://www.example.com/' because it violates the following Content Security Policy directive: "child-src 'self'". Note that 'frame-src' was not explicitly set, so 'child-src' is used as a fallback.
I found a solution on here (Injecting iframe into page with restrictive Content Security Policy), which requires injecting a local iframe which then comatins another iframe that references the remote url. This is supposed to bypass the sontent security policy. But for some reason, it does not seem to work in my case. Am I missing something or has the chrome security policy changed?
Below are portions of my extension that pertain to this issue. Note - this code is not the prettiest as I've been hacking around trying to get this to work.
The way this works right now is background.js sends a message to inject.js. inject.js inserts the first iframe, referencing the local file infobar.html. This page is our main user interface, we want the remote html page displayed in an iframe as part of this page. Then infobar.js inserts an iframe referencing the local file frame.html. Finally, frame.html has an iframe hard coded to our remote url.
Based on the previous answer, only the first iframe should have been subject to the content security policy. However, that doesn't seem to be the case here, as the one referencing example.com is actually 3 iframes deep.
manifest.json
{
...
"content_security_policy": "script-src 'self'; object-src 'self'; frame-src https://www.example.com; child-src https://www.example.com",
"background": {
"scripts": [
"js/jquery/jquery.min.js",
"src/bg/background.min.js"
],
"persistent": true
},
...
"content_scripts": [
{
...
"css": [
...
"src/inject/inject.min.css"
],
"js": [
...
"src/inject/inject.min.js"
]
}
],
"externally_connectable": {
"matches": [
"*://localhost/*",
"*://*.example.com/*
]
},
"web_accessible_resources": [
"src/inject/inject.html",
"src/inject/infobar.html",
"src/inject/infobar.min.js",
"src/inject/frame.html"
],
"sandbox": {
"pages": [
"src/inject/infobar.html",
"src/inject/frame.html"
]
}
}
inject.js
var iframe = document.createElement("iframe");
iframe.scrolling = "no";
iframe.style.cssText = "display:none;";
...
$(iframe).load(function () {
var message = {
command: "render-frame",
context: data,
frameUrl: chrome.runtime.getURL("src/inject/frame.html")
};
iframe.contentWindow.postMessage(message, '*');
iframe.style.cssText = "border: 0px; overflow: visible; padding: 0px; right: auto; width: 100%; height: " + toolbarHeight + "px; top: 0px; left: 0px; z-index: 2147483647; box-shadow: rgba(0, 0, 0, 0.498039) 0px 3px 10px; position: fixed; display: none;";
});
...
iframe.src = chrome.runtime.getURL("src/inject/infobar.html");
...
document.documentElement.appendChild(iframe);
infobar.html
Simple HTML page. Nothing pertinent in there. References infobar.js.
infobar.js
window.addEventListener("message", function (event) {
var command = event.data.command;
switch (command) {
case "render-frame":
var frame = document.createElement("iframe");
frame.scrolling = "no";
frame.src = event.data.frameUrl;
document.getElementById("content").appendChild(frame);
...
break;
}
});
frame.html
<html>
<head>
<style>
html, body, iframe, h2 {
margin: 0;
border: 0;
padding: 0;
display: block;
width: 100vw;
height: 100vh;
background: white;
color: black;
}
</style>
</head>
<body>
<iframe src="https://www.example.com/page.html"></iframe>
</body>
</html>
The proper way is to use the chrome.webRequest API in your background script and intercept HTTP responses.
You can then override response headers to modify Content-Security-Policy header. You can also modify X-Frame-Options header (if required).
Documentation: chrome.webRequest

Resources