I'm trying to run the example Neo4j Node project in Docker containers but I'm having an issue with the Node part. The project runs fine locally but when I run it in a docker container I get this error:
const neo4j = window.neo4j;
^
ReferenceError: window is not defined
I have pretty much no JavaScript / Node experience so just looking for any help to point me in the right direciton.
My dockerfile looks like this:
FROM node:10
WORKDIR /app
COPY package.json /app
COPY package-lock.json /app
RUN npm config set strict-ssl false
RUN npm cache clean --force && npm install && npm install -g serve
#RUN npm install
COPY . /app
RUN npm run build
COPY serve.json dist/serve.json
CMD ["node", "src/app.js"]
EXPOSE 8080
The demo project is: https://github.com/neo4j-examples/movies-javascript-bolt
UPDATE
The comment from Amir seems to have solved the original issue. This was to change
const neo4j = window.neo4j;
to
const neo4j = require("neo4j-driver");
with neo4j-driver being the name of the module.
Now I'm getting this similar issue if anyone has any ideas:
$(function () {
^
ReferenceError: $ is not defined
Related
When I run npm start, I get this error. What is the solution for this?
This issue has been addressed here, you can refer to it.
Complete solution is
First add Poweshell to PATH as %SystemRoot%/system32/WindowsPowerShell/v1.0.
open powershell as admin and write this command Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force.
last thing fire npm-windows-upgrade.
Check your node version. update node & npm
try sudo npm start if you are in macOS or linux
try to download create-react-app again npm i -g create-react-app
try to create the app in another folder create-react-app APPNAME
Still not working? Then delete node module folder and run npm install
Not yet? delete both node module & package-lock.json and npm install
Try to run on another PORT
I have a file server.js in which I am starting multiple servers.
eg.
var engine = require('engine.io');
var server = engine.listen(80);
And if the engineio module is not installed in the current directory by using the
npm install engine.io
It throws an error
Error: Cannot find module 'engine.io'
Now on a machine where this server has to be deployed I want handle all these npm module installation dependencies from the script file itself.
How can i do this from my server.js file only
UPDATE
As suggested i tried following the post
Can I install a NPM package from javascript running in Node.js?
but it throws an error when it searches for a node module "npm"
at :
var npm = require("npm");
Reason : i dont have the node modules installed on my machine. ( and so its not having node_modules folder in my working directory)
Also,
I created a batch file in my working directory and put the following into it
npm install engine.io
npm install eyes
And when i run it,
It only installs the first module and then exits
Thanks
I'm trying to install and use grunt.
I install using npm install grunt -g
it seems to install -
grunt#0.4.3 /Users/me/.node/lib/node_modules/grunt
when I open up a new tab in terminal and run grunt I get
-bash: grunt: command not found
My path looks like this
$ echo $PATH
/Users/me/.rbenv/shims:/Users/me/.rbenv/shims:/bin:/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/local/mysql/bin:/usr/local/mysql/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/local/git/bin
Any advice? This is killing me.
I've installed grunt-cli too, still not working -
npm install grunt-cli -g
/Users/me/.node/bin/grunt -> /Users/me/.node/lib/node_modules/grunt-cli/bin/grunt
I open a new tab
-bash: grunt: command not found
I installed node using the node installer. I'm on OSX.
I've just added /.node/bin to my path, see below -
echo $PATH
/Users/me/.rbenv/shims:/Users/me/.rbenv/shims:/.node/bin:/bin:/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/local/mysql/bin:/usr/local/mysql/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/.node/bin:/opt/X11/bin:/usr/local/git/bin
It's still not working.
Your path don't contain ~/.node/bin where apparently your globally installed npm binaries are kept.
You need to fix that if you expect said binaries to be picked-up.
Either way, this points out that you missed a step in your node / npm installation. How did you installed node exactly?
I don't know what other people do, but I'm using node from homebrew, which should take care of that for you (I assume from the paths you list that you are on OSX).
try to install grunt globally
$ sudo npm install grunt -G
You may have Grunt 0.4.3 installed globally but nothing installed locally.
Run $ grunt --version to find which version you are on. At this point you'll only be knowing that you do have Grunt installed in your system. But to run Grunt at the directory level (also known as "project level") you'll need to be specific - because not every project may require the Grunt version you have installed globally.
Create a package.json file in the directory you mean to have your project on. Let's call it the project's root folder.
{
"name" : "MyProject",
"version" : "0.1.0",
"author" : "My name",
"private" : true,
"devDependencies" : {
"grunt" : "~0.4.2"
}
}
Navigate to the project's root folder and run $ npm install. The specified Grunt version will be installed as a dependency to the project.
Smile, you have Grunt up and running! :)
Sometimes another version or just a wrong path is referenced in the npm config file instead of the installed version.
This may cause node/npm to misplace global modules.
To check and fix:
In cmd line type: npm config list
You should get a list of configuration values, one of them is prefix.
Make sure the path in prefix is the same path (only without node.exe) as the actually installed node.exe path.
(this path is listed further down as node bin location)
If it's not, change it:
Either in the config file (in your user folder, named .npmrc)
Or, via cmd line: npm config set prefix "C:\Program Files\nodejs" (change path if needed)
Reinstall the module/package you tried to install, don't forget -g for global.
I'm working with Mac OS X 10.7.5 and I'm using Grunt to concate some js files and minify them. Now I want to also minify my css files. As grunt does not provide any functionality I wanted to install a grunt plugin for that.
According to the instructions i have to cd into my projects root folder and install the plugin with npm. So I did the following:
cd <PROJECT_ROOT>
npm install grunt-contrib-css
The instructions for the plugin are here: https://npmjs.org/package/grunt-contrib-mincss
The I opened my grunt.js file and added
grunt.loadNpmTasks('grunt-contrib-mincss');
But when I try to run grunt I just get
Local Npm module "grunt-contrib-mincss" not found. Is it installed?
<WARN> Task "mincss" not found. Use --force to continue. </WARN>
The installation works without any problem and npm ls does list the module.
Any ideas what I have done wrong? Many Thanks!
UPDATED
When I cd into a project like so
cd ~/Sites/path/to/project
and then install the plugin
sudo npm install grunt-contrib-mincss
the module is actually installed in
~/node_modules/grunt-contrib-mincss
I could hard copy the files into my projects root directory (which works) but it's kind of strange isn't it?
UPDATE 2
I've updated node and tried it again. Below is the console output.
me:~ Fritz$ node -v
v0.8.10
me:~ Fritz$ npm -v
1.1.62
me:~ Fritz$ mkdir ./Sites/npm-test
me:~ Fritz$ cd ./Sites/npm-test/
me:npm-test Fritz$ sudo npm install grunt-contrib-mincss
Password:
npm http GET https://registry.npmjs.org/grunt-contrib-mincss
npm http 304 https://registry.npmjs.org/grunt-contrib-mincss
npm http GET https://registry.npmjs.org/gzip-js
npm http GET https://registry.npmjs.org/clean-css
npm http GET https://registry.npmjs.org/grunt-contrib-lib
npm http 304 https://registry.npmjs.org/gzip-js
npm http 304 https://registry.npmjs.org/clean-css
npm http 304 https://registry.npmjs.org/grunt-contrib-lib
npm http GET https://registry.npmjs.org/crc32
npm http GET https://registry.npmjs.org/deflate-js
npm http GET https://registry.npmjs.org/optimist
npm http 304 https://registry.npmjs.org/deflate-js
npm http 304 https://registry.npmjs.org/crc32
npm http 304 https://registry.npmjs.org/optimist
npm http GET https://registry.npmjs.org/wordwrap
npm http 304 https://registry.npmjs.org/wordwrap
grunt-contrib-mincss#0.3.0 ../../node_modules/grunt-contrib-mincss
├── grunt-contrib-lib#0.3.0
├── gzip-js#0.3.1 (crc32#0.2.2, deflate-js#0.2.2)
└── clean-css#0.4.2 (optimist#0.3.4)
Why is the plugin installed outside? Or is there a way to define the actual location where it is installed?
I had a similar issue on Ubuntu 12.04 for the module grunt-jasmine-task (same error message as above). This solved the issue for me:
Manually create the folder node_modules in the root of the project.
Run npm install grunt-jasmine-task again.
This way to install worked for me:
cd <PROJECT_ROOT>.
Run npm install grunt-contrib-mincss.
Created test file in the current dir with the following testing content:
module.exports = function(grunt) {
grunt.initConfig({
mincss: {
compress: {
files: {
"path/to/output.css": ["path/to/input_one.css", "path/to/input_two.css"]
}
}
}
});
grunt.loadNpmTasks('grunt-contrib-mincss');
grunt.registerTask('default', 'mincss');
};
My directory structure looks like this at this moment (please check this, if some files are not there or in some other folder, then it can be reason why it doesn't work):
<PROJECT_ROOT> /
node_modules /
grunt-contrib-mincss/
grunt.js
Run grunt in terminal.
Script worked.
Possible reasons why it didn't work in your case:
You installed plugin globally (with -g argument).
You installed it in some subfolder (grunt.js and node_modules must be in the same folder).
Please check it.
I have seen cases where not having a package.json file present caused the modules to be installed globally. I'm not sure what version was running at the time, as it was not my machine.
Next time try running npm init prior to installing modules. After that, install using npm install grunt-contrib-css --save to have it added to your package.json file. You can also use --save-dev to have it added to your devDependencies.
In my case, I forgot to add:
grunt.loadNpmTasks('grunt-jsdoc-plugin');
to grunt.js, so it should look like this:
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
jsdoc : {
dist : {
src: ['frontend/js/**/*.js'],
dest: 'docs/frontend'
}
}
});
grunt.loadNpmTasks('grunt-jsdoc-plugin');
};
If you take a look under the grunt-contrib-mincss folder, there is a readme file, they changed name from grunt-contrib-mincss to grunt-contrib-cssmin.
anyway, it's not your(and mine) fault. XD
When I try to run the app.js file created by express, I get the following error:
$ node app.js
node.js:134
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: Cannot find module 'express'
at Function._resolveFilename (module.js:320:11)
When I type in express --version I get a return statement of 2.3.3. I used npm to install express. I had to manually make npm using these instructions:
git clone http://github.com/isaacs/npm.git
cd npm
sudo make install
The error is Error: Cannot find module 'express'.
Do I need to do something after installing npm and express in order to make express see the modules created by npm?
My node is version: 0.4.6
My express is version: 2.3.3
My npm is version: 1.0.6
Express is installed globally. I used the -g flag to install it.
Edit: When I try "node -e require.paths" I get:
[ '/home/user/.node_modules',
'/home/user/.node_libraries',
'/usr/local/lib/node' ]
So, node isn't detecting the npm installation. How do I get node to detect the npm installation?
Install express
npm install -g express
Create a new app
express your_app
cd into app directory
cd your_app
use npm link to resolve modules
npm link express
Use local installs for require(), and global installs for command-line apps.
If you need both, use the npm link command.
On Ubuntu 12.04 you have to add the export NODE_PATH=/usr/local/lib/node_modules to your /.bashrc to use globally installed modules.
It appears that while npm had been updated to install global modules into /usr/local/lib/node_modules, Node's own require.paths does not yet reflect this change.
There are two reasonable solutions:
Add the following code to the top of your application:
require.paths.push('/usr/local/lib/node_modules');
Pro: non-invasive, easy to add
Con: requires discipline, future versions of node will restrict access to require.paths
As root, execute:
ln -s /usr/local/lib/node_modules /usr/local/lib/node
Pro: reasonably non-invasive
Con: requires root, modifies linux fs, might not survive system updates
I had the same problem. This worked for me though:
Seems like npm (now?) installs node modules to /usr/local/lib/node_modules/ and not /usr/local/lib/node/
What I did was simply to copy everything from node_modules to node: sudo cp -r /usr/local/lib/node_modules/* usr/local/lib/node/ and now it seems to be working for me.
Hope this helps you :-)
What about NODE_PATH=/usr/local/lib/node_modules in .bashrc or .bash_profile? I think it's the real correct way.
Set NODE_PATH=NODE_HOME\node_modules.
I'm using windows 7 and it works fine.
It may happen, if you're using windows, that the environment variable NODE_PATH is not set, and thus when you execute node fileName.js it won't find the libraries.
Check for the variable on your console, and if not present, create it. Give it the NODE_HOME\node_modules value, where NODE_HOME is your node install dir. This path is where npm install puts every module upon downloading.
require.paths is removed, use the NODE_PATH environment variable instead.
It looks like the easiest way to do this is to run npm install from your app's folder. This tells npm to hook everything up.
It's the last instruction after express <appname>:
...
dont forget to install dependencies:
$ cd <appname> && npm install
Finally with Linux a good way to do is to use the command : sudo apt-get install node-express
But with express 4 we must use express-generator to make app skeleton, install it with 'npm install express-generator -g', and then run 'express myapp' command.
see also install express
for mac users
cd /usr/local/lib/node
sudo ln -s ../node_modules/* ./$1
I installed gulp and when I ran this gulp command in the command line I got a gulp: command not found error. It appeared that it installed gulp in my local folder that is /home/YOURUSERNAME/.node/lib/node_modules and not in the global npm folder.
You can check npm root folder by running this command: npm root -g, which was returning my personal directory /home/YOURUSERNAME/.node/lib/node_modules and not the expected /usr/local/lib/node_modules.
You can fix this by running npm config set prefix /usr/local command.
For all problems with express with a mac computer:
The solution is:
chown to your user the .npm folder :
sudo chown -R Webmaste /Users/webmaste/.npm/
At your test folder or your folder:
sudo npm install -g express#2.5.8
Invoke express from your actual location:
/usr/local/share/npm/bin/express
sudo cd . && npm install
Finally:
node app
the final message in the console should look like this:
Express server listening on port 3000 in development mode