To convert string to number with Node.js, we call the parseInt function.
For instance, we write
const year = parseInt(req.params.year, 10);
to call parseInt to convert req.params.year to a decimal integer.
Web developer specializing in React, Vue, and front end development.
To convert string to number with Node.js, we call the parseInt function.
For instance, we write
const year = parseInt(req.params.year, 10);
to call parseInt to convert req.params.year to a decimal integer.
To update npm on Windows, we run npm install.
We run
npm install npm@latest
to update npm to the latest version.
To delete a directory that is not empty with Node, we install rimraf.
To install it, we run
npm install rimraf
Then we write
rmdir = require("rimraf");
rmdir("some/directory/with/files", (error) => {});
to call rmdir to remove the some/directory/with/files folder.
If there’s any error, then we get the error from the callback.
To install and run MongoDB on Mac OS, we install MongoDB with brew install.
We run
brew install mongodb
to install mongodb.
Then we make folder to hold the Mongo data files with
mkdir -p /data/db
Then we set permissions with
sudo chown -R `id -un` /data/db
We then run the server with
mongod
We run the Mongo command line utility with mongo.
To fix npm install gives error "can’t find a package.json file" with JavaScript, we run npm install with the package name.
For instance, we run
npm install express
to install the express package.
Then a package.json file is created automatically with a list of installed packages.