Npm: Getting cannot get / error after publishing my package - node.js

I am having a npm package which serves as a local host. What I want is after user use npm install -g to install it, they can use the command easydx to run the local host and web pages can be served as in a static server.
During development, it works fine with npm start and the pages can successfully open at localhost:3666. But when I publish the package and tested it using npm install -g to install it. After easydx successfully fires the server, localhost:3666 get the cannot get / error.
My package contains the line:
"bin": {
"easydx": "index.js"
},
and my index.js file begins with
#! /usr/bin/env node
So what is going wrong here?
In my index.js file:
I have used:
app.use(express.static('dist'));
to serve the static web files. And have used express routes for the web service.

Related

angular universal host sitegroud

I have Created a new angular project and converted it to universal. After running npm run build:ssr i got file structure like this
dist
----my-project
---browser
---server
and when i run command npm run serve:ssr my server is running on port localhost:4000 but now i want to host my project on my siteground hosting server where i uplaod my dist folder file (browser and server) using filezila, but i got an error 404 then i upload package.json file and connect through ssh to my terminal and install first node after that i put command npm install on derectory where i have upload all file with package.json but again i am fail. please if any one have idea to help me.

can we deploy an react js application without source(src folder) code locally

some background:this is my first react application and my assumption is build in react is similar to binary files in c++
question : this is for a react application which sole purpose is to run locally. is there anyway we can do npm start only with build
have tried to delete the src folder after building.
expected result is the app should run as usual.
actual result : app crashes saying, index.js file is missing
npm start won`t work with build version,
you need to install serve and run build using serve locally on your machine
npm install -g serve
serve -s build
ref: https://facebook.github.io/create-react-app/docs/deployment

Node js - how to publish a package and let user run a single command to start the server

I have made a npm package for the first time. For my daily dev, I have used npm start to start the server and then user can use localhost:3000 to view the pages.
When I try to publish that to end users, I can still ask people to use npm install > npm start to use the package. However, it doesn't sound decent.
How can I make people being able to use:
npm install myPackage
myPackage start
to start the server and then they can open localhost: 3000 directly?
You can make a global module and attach it to a bin command.
Here's the tutorial for that by npm itself.
In your package.json file, you can add this:
"bin": {
"your-command": "bin/path/to/js/file.js"
}
and then whenever the user installs your module globally, then they can directly type in that command and the js file will execute your code.
You need to create global package for your module so that it can be installed
npm i -g module
then provide some config file like gulpfile.js which will be used by your package to carry out the task to start server any other task

npm package error - Cannot find module 'users-node'

I installed the users-node package on my Windows7 machine using npm install users-node - great success!
Code:
...
var usermgr = require('users-node')(options, app);
...
But when I run my node server I get:
Error: Cannot find moduel 'users-node'
I implemented the code suggested on this page: https://npmjs.org/package/users-node but I could not download the repository from GitHub - link is broken: https://github.com/dpweb/users-node.
What do I need to do to implement users-node? I need to do users management, so do simple user login on a chat app using Node.js, Socket.io and express.
Are you sure that you didn't install it with -g option?
If so you need to set NODE_PATH environment variable.
The default path for Windows is:
%AppData%\Roaming\npm\node_modules
In case you didn't install it globally, you must place your app.js file beside the node_modules directory which is created after you run npm install users-node

node.js: cannot find module 'request'

I installed request module, and getting the error:
module.js:340
throw err;
^
Error: Cannot find module 'request'
i've read all the posts about this error, and understand that this is because module requests is not globally found, but i've already tried the 2 suggestions
npm install request -g
should this install it in /usr/loca/bin ? because i don't see it there.
and
sudo npm link
/usr/local/lib/node_modules/request -> /Users/soulsonic/dev/sandbox/node_test/request
i restarted terminal after each command, but keep getting the cannot find module error.
update
there must have been some sort of conflict in my initial directory, because "npm install request" was not adding "request" under node_modules (there 10 others in there) ..
after switching to a new directory it just worked.
if i run it with -g switch, i do see it bing installed to /usr/local/lib/node_modules/request.
it seems that i just need to update my profile so that above path is automatically added.
Go to directory of your project
mkdir TestProject
cd TestProject
Make this directory a root of your project (this will create a default package.json file)
npm init --yes
Install required npm module and save it as a project dependency (it will appear in package.json)
npm install request --save
Create a test.js file in project directory with code from package example
var request = require('request');
request('http://www.google.com', function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body); // Print the google web page.
}
});
Your project directory should look like this
TestProject/
- node_modules/
- package.json
- test.js
Now just run node inside your project directory
node test.js
You should simply install request locally within your project.
Just cd to the folder containing your js file and run
npm install request
I had same problem, for me npm install request --save solved the problem. Hope it helps.
I have met the same problem as I install it globally, then I try to install it locally, and it work.
if some module you cant find, try with Static URI, for example:
var Mustache = require("/media/fabio/Datos/Express/2_required_a_module/node_modules/mustache/mustache.js");
This example, run on Ubuntu Gnome 16.04 of 64 bits, node -v: v4.2.6, npm: 3.5.2
Refer to: Blog of Ben Nadel
I tried installing the module locally with version and it worked!!
npm install request#^2.*
Thanks.
I was running into the same problem, here is how I got it working..
open terminal:
mkdir testExpress
cd testExpress
npm install request
or
sudo npm install -g request // If you would like to globally install.
now don't use
node app.js or node test.js, you will run into this problem doing so. You can also print the problem that is being cause by using this command.. "node -p app.js"
The above command to start nodeJs has been deprecated. Instead use
npm start
You should see this..
testExpress#0.0.0 start /Users/{username}/testExpress
node ./bin/www
Open your web browser and check for localhost:3000
You should see Express install (Welcome to Express)
ReferenceError: Can't find variable: require.
You have installed "npm", you can run as normal the script to a "localhost" "127.0.0.1".
When you use the http.clientRequest() with "options" in a "npm" you need to install "RequireJS" inside of the module.
A module is any file or directory in the node_modules directory that can be loaded by the Node.
Install "RequiereJS" for to make work the http.clientRequest(options).

Resources