It says that it can't find prompt-sync and exits with code=1
const prompt = require('prompt-sync')();
var fname = prompt("Enter your first name : ");
var lname = prompt("Enter your last name : ");
console.log("Your full name is : ",fname + " " + lname);
I tried to changeing
console.log("Your full name is : ",fname,lname);
to
console.log("Your full name is : ",fname + " " + lname);
You can replicate the error with just this:
const prompt = require('prompt-sync')();
This means that the problem occurs when trying to find "prompt-sync".
The documentation of prompt-sync is not ideal
I've had a quick look at https://www.npmjs.com/package/prompt-sync
It mentions the optional installation of a history module, but does not mention the main installation. This may be why it is not working for you.
How to fix
On the system command line (Windows terminal or Mac terminal), with the working directory set to the directory of your project, type:
npm install prompt-sync
If that command gives an error, first install npm itself.
Once prompt-sync is installed, you should be able to run your code.
Related
I am new to JavaScript and HTML so i was doing some tests and I was using readline and I came across the error. I have installed everything needed so it should work. Here is my js code because thats it the only main code.
import readline from './readline';
var name = readline("What is your name?");
println("Hello " + name + "!");
// Prints out the variable type
println("Name is a " + typeof name);
I was trying to take an input from the user and print it in the input box.
When I try to check netlify is install or not then show me this error:
: The term '' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path
was included, verify that the path is correct and try again.
At C:\Users\alami\AppData\Roaming\npm\netlify.ps1:1 char:1
+ ...
+ ~
+ CategoryInfo : ObjectNotFound: (:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
After successfully install npm i -g netlify-cli then I get this error
I have tried to fixed this problem
Any suggestion please
I use the following command when building an ionic project for desktop
ionic cordova build browser --prod
Which results in the following file being generated
build/main.js
However I would like to be able to add a version number to the generated file automatically as part of the build process. So would end up with something like
build/main.js?version=1.00
as to avoid needing to clear the browser cache after every prod build.
Is there a flag for this, or is it something I must do manually?
Any advice would be great!
EDIT:
My solution is on GitHub for anyone interested!
https://github.com/RichardM99/ionic-3-version-build-file-hook
Here's some advice - You can create a cordova hook.
Hooks are scripts that you want to be executed at different stages of the build process. In your case, you are looking at a script which renames the main.js file after the build event is finished, or in other words a 'after_build' type hook.
The script will usually be a Node.js file, although you can have other types of scripts executed as well.
One more thing. Since you want to get around cache, you wont be renaming the file itself. What you will want to do is rather replace the reference to "main.js" in you "index.html" to include a random or maybe your actual version number.
I have pointed you in a direction, but won't spoonfeed. Look up documentation on cordova hooks. They are super simple if you understand Javascript/Node
Something like this should get the job done:
var index_orig = fs.readFileSync(path-to-index.html, 'utf8');
var index_new = index_orig.replace("main.js", "main.js?version="+version_num);
fs.writeFileSync(path-to-index.html, index_new, 'utf8');
If you want the actual build number, you can read your config.xml and parse it to get it's value.
Hope it helps.
I wrote blog long time ago
In my build pipeline i have command to set version
version "$(app.versionPrefix)$(Build.BuildNumber)"
$(app.versionPrefix) - is a prefix version such as 0.1.
$(Build.BuildNumber) - is build version
Then I have environment file
export const environment = {
apiUrl: 'https://....',
production: true,
version: '0.0.57'
}
Then i have js script to update version in environment and config.xml
var replace = require('replace-in-file');
var package = require("./package.json");
var buildVersion = package.version;
const options = {
files: ['config.xml'],
from: /" version="([0-9]*.[0-9]*.[0-9]*)"/g,
to: "\" version=\""+ buildVersion + "\"",
allowEmptyPaths: false,
};
const optionsEnv = {
files: ['src/environments/environment.prod.ts'],
from: /version: '(.*)'/g,
to: "version: '"+ buildVersion + "' ",
allowEmptyPaths: false,
};
try {
let changedFiles = replace.sync(options);
if (changedFiles == 0) {
throw "Please make sure that file '" + options.files + "' has \"version: ''\"";
}
changedFiles = replace.sync(optionsEnv);
if (changedFiles == 0) {
throw "Please make sure that file '" + optionsEnv.files + "' has \"version: ''\"";
}
console.log('Build version set: "' + options.to + '"');
}
catch (error) {
console.error('Error occurred:', error);
throw error
}
NOTE: you need to install plugin replace-in-file
Then in build pipe line I am running this script
node ./replace.build.js
In your case if you need only for browser you can tune script.
I have been trying to use node.js to follow a log file that is on a remote server. I used "sequest" to connect to the server. No problem there. It even allows me to run commands, but when I try "tail -f" it fails doesn't return anything. Removing the -f works, I asume it is because there command is not "done" so there is nothing to return yet? Am I missing something? Is there another alternative to get the output of a 'tail -f' command on a remote location?
var sequest = require('sequest');
var conf = require('./config/properties.js');
var prop = conf.ssh.dev;
var seq = sequest.connect(prop.host,{password:prop.password});
seq('tail -f -n 100 /interwoven/LiveSiteDisplayServices/runtime/tomcat/logs/catalina.out', function (e, stdout) {
console.log(stdout.split('\n'));
});
Following Adrian Lynch recommendation I used piping specified in the sequest documentation at npmjs.com/package/sequest. It ended up looking something like this:
var sequest = require('sequest');
var conf = require('./config/properties.js');
var prop = conf.ssh.dev;
var seq = sequest(prop.host, { password: prop.password});
seq.pipe(process.stdout);
seq.write('tail -f -n 100 /interwoven/LiveSiteDisplayServices/runtime/tomcat/logs/catalina.out');
I am trying to run this script below via the command line
var argv = require('optimist').argv,
$ = require('jquery'),
fs = require('fs');
var file = argv._[0];
var html = fs.readFileSync(file, 'UTF-8');
$(html).find('p').each(function(index) {
var content = $(this).html();
console.log('Paragraph ' + (index + 1) + ': ' + content);
}); //script.js
The command is $ node script.js page.html where page.html is the argument
The error I get is:
./node_modules/jquery/dist/jquery.js:29
throw new Error( "jQuery requires a window with a document" );
Error: jQuery requires a window with a document
at module.exports (./node_modules/jquery/dist/jquery.js:29:12)
...
I am using jquery-2.1.3. I know that this used to work, once upon a time, but it looks like something has changed.
Also I did follow the instructions at http://rkulla.blogspot.com/2014/04/using-browserify-with-jquery-backbonejs.html but I am still getting the same error.
Any help to fix this error would be greatly appreciated. Thank you very much!
See this answer. The npm package for jQuery no longer includes jsdom, which provides the DOM environment needed to work with jQuery on the server.
On the other hand, you could just use cheerio, an implementation of jQuery for the server, to parse the html and use jQuery's selectors.
var argv = require('optimist').argv,
$ = require('cheerio'),
fs = require('fs');
var file = argv._[0];
...
I could not install jsdom for the life of me so I gave up on that, but cheerio (npm install worked very smoothly after editing package.json) solved the problem (see code modification above). Thank you!