Categories
JavaScript Answers

How to run Node npm install without SSL?

To run Node npm install without SSL, we set the registry to the non-secure registry URL.

To do this, we run

npm config set registry http://registry.npmjs.org/

to set the npm registry URL to http://registry.npmjs.org/.

Categories
JavaScript Answers

How to send custom data along with handshake data in Node socket.io?

To send custom data along with handshake data in Node socket.io, we get the handshake data from the socket.manager.handshaken property.

For instance, we write

const socket = io.connect(window.location.origin, {
  query: "loggeduser=user1",
});

io.sockets.on("connection", (socket) => {
  const endp = socket.manager.handshaken[socket.id].address;
  console.log(socket.manager.handshaken[socket.id].query.user);
});

to call connect to make the connection.

Then we listen for the connection event with on.

In the callback, we get the handshake data with socket.manager.handshaken

And we get the query string from the query property.

Categories
JavaScript Answers

How to fix Node already installed but not linked issue on Mac?

To fix Node already installed but not linked issue on Mac, we change the permission of a few folders and run brew link.

To fix this, we

  1. Run sudo chmod 776 /usr/local/lib to change the permission of the /usr/local/lib to make the folder readable, writable and executable.

  2. Run brew link --overwrite node to link Node.

  3. Run sudo chmod 755 /usr/local/lib to change the directory to be readable and executable.

Categories
JavaScript Answers

How to fix react-native run-android is unrecognized error with Node?

To fix react-native run-android is unrecognized error with Node, we should run this in the React Native project folder.

We run cd to change to the React Native project folder before running react-native run-android.

Categories
JavaScript Answers

How to fix Sass Loader Error: Invalid options object that does not match the API schema with JavaScript?

To fix Sass Loader Error: Invalid options object that does not match the API schema with JavaScript, we make sure the Webpack config has properties in the right places.

For instance, we write

module.exports = {
  loader: "sass-loader",
  options: {
    sassOptions: {
      indentedSyntax: true,
    },
  },
};

in webpack.config.js, to add the indentedSyntax property into sassOptions.