npm fast-lorem-ipsum not working in nodejs - node.js

`var fastLoremIpsum = require('fast-lorem-ipsum').fastLoremIpsum;
console.log(fastLoremIpsum(10,'c'));`
I was trying to use fast-lorem-ipsum npm package but on executing above code in nodejs file,instead of getting lorem-ipsum text i am getting 'undefined' as console output.
What should i do ?

If you look at the documentation for the package, the function you're looking for should be accessed like this —
var fastLoremIpsum = require('fast-lorem-ipsum').fastLoremIpsum;
console.log(fastLoremIpsum(10,'c'));

Related

Module not found: Error: Can't resolve 'fs' when trying to use a NodeJS library

I initiated a basic ReactJS app using npx create-react-app, then I ejected using npm run eject. Now when I am trying to import the Casual library by import casual from 'casual';, I get the following error:
Compiled with problems:
ERROR in ./node_modules/casual/src/casual.js 3:13-37
Module not found: Error: Can't resolve 'fs'
in '/home/me/project/node_modules/casual/src'
And the code around line number 3 in casual.js looks like this:
var helpers = require('./helpers');
var exists = require('fs').existsSync;
var safe_require = function(filename) {
if (exists(filename + '.js')) {
return require(filename);
}
return {};
};
...
I found answers to similar questions. Those were mainly Node or Angular related. I also tried answers suggesting some changes in webpack config, but no luck.
The reason is Casual doesn't work on the front end. It runs on Node.js only.
You need to install maybe a new package to make things work.
Fs is unavailable on the browser so it won't work. Instead, you should use casual-browserify, it will work on browsers.

Error API body type after build with node adapter

My app on SvelteKit + ts. I build npm run build (node adapter), with npm run preview (and with npm run dev) everything works. With node build
export async function post ({body}) {
try {
const login = body.get ('login');
error TypeError: body.get is not a function.
Content-Type request: application / x-www-form-urlencoded. Body is Uint8Array(34) in building app.
As I understand it, you need to screw the bode-parser somewhere. Or how to solve this?
Thanks!
Update #sveltejs/kit to 1.0.0-next.165 fix it =)

Cannot call require('fs') with PhantomJS runner

I've been trying to use the FS API in PhantomJS, but I get an error I'm not able to understand when I run the following code
private[scalajssupport] object PhantomFile {
val fs: PhantomFS = js.Dynamic.global.require("fs").asInstanceOf[PhantomFS]
}
The error I get is:
TypeError: undefined is not a constructor (evaluating '$g["require"]("fs")')
However, when I run
var fs = global["require"]("fs")
directly in the PhantomJS REPL, it's working fine.
It turns out that when using PhantomJS to run scala.js code, it is ran in a sandbox with the "webpage" module, which does not have access to require.
The only way to write to the filesystem was to define a callback in onCallback, as seen in the answer to this StackOverflow question.

Meteor: "ReferenceError: fs is not defined"

Losing my mind with this one..
Getting "fs is not defined" on meteor when trying to read a file:
var data = fs.readFileSync(filepathHidden);
I have this package: cfs:filesystem 0.1.2 on Meteor 1.1.0.2
Funny thing here is that if I write in meteor shell fs it prints object and it seems to have lot of functions etc stuff. But the thing here is that after writing fs in meteor shell my code starts to work!? And if I close meteor server and then start it again my server code keeps nagging until I run fs in meteor shell...
Can someone please explain what happens in this case? And how to achieve same thing in my code..
You just need to load it in via npm. In meteor that looks like:
var fs = Npm.require('fs');
var data = fs.readFileSync(filepathHidden);

Problems directly using PhantomJS in node.js

I'm attempting to use PhantomJS, and I've installed it via NPM.
I can't seem to run any of the of the examples, in fact I can't even run:
var page = require('webpage').create();
I get the error:
Error: Cannot find module 'webpage'
Is there anything i'm missing? I'm using a few other modules that I've installed via NPM in the same directory with no issues
PhantomJS is not for Node.js. You are likely running the examples through node binary.
Read the Getting Started documentation carefully and you'll see that every single PhantomJS example need to be invoked like:
phantomjs hello.js
Note that there is a bridge between Node.js and PhantomJS. In that case, you need to follow the given examples for that particular bridge (there are a few different ones).
You can use something like this:
var page = new WebPage();
Example of code :
var page = new WebPage();
page.open('http://example.com', function(status) {
console.log("Status: " + status);
if(status === "success") {
page.render('example.png');
}
phantom.exit();
});

Resources