I know that this has been asked before but none of the solutions worked for me. Whenever I try to install express, it seems to work just fine, displaying this message:
npm WARN website#1.0.0 No description
+ express#4.17.1
updated 1 package and audited 50 packages in 6.581s
found 0 vulnerabilities
However, when I try to run my program that uses express:
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:889:15)
at Module.require (internal/modules/cjs/loader.js:961:19)
at require (internal/modules/cjs/helpers.js:92:18)
at Object.<anonymous> (C:\Users\darcy\OneDrive\Sutton\Website\server.js:2:15)
at Module._compile (internal/modules/cjs/loader.js:1072:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
at Module.load (internal/modules/cjs/loader.js:937:32)
at Function.Module._load (internal/modules/cjs/loader.js:778:12)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12) {
code: 'MODULE_NOT_FOUND',`
Here is my code:
let express = require("express");
let account = require("accountBack");
let shop = require("shopBack")
let serverConnection = express();
serverConnection.listen(3000, () => {});
serverConnection.use(express.static("public"));
serverConnection.use(express.json());
serverConnection.post("/account", account.accountServer);
serverConnection.get("/shop", shop.sendShop);
I am using code from other files (hence the
extra 2 require statements) but what they do I do not believe to be significant.
Here are the commands that I am typing in:
npm init
npm install express
node server.js
It does not appear from the error that express is gettinginstalled correctly, but I'm not sure. Is it a problem with the commands that I a typing in or something else? Any help would be appreciated.
For the internal module, you should import like this
const account = require("./accountBack");
const shop = require("./shopBack")
Unless you publish those modules to npm registry (private/public), then you can import like what you did.
i will explain my problem, im trying to deploy an Meteor App on EC2 AWS (Ubuntu 16), the code is download from bitbucket and i was trying deploy with Mup.
Mup Setup has no problems, but when using the Mup deploy command, it progresses to "minifying app code" and never goes forward.
Meteor 1.7.0.4
node v 10.9.0
mup --version
1.4.5
Attach the Mup.js file and the putty session
module.exports = {
servers: {
one: {
// TODO: set host address, username, and authentication method
host: 'xxxx',
username: 'ubuntu',
pem: '../xxxx.pem'
// password: 'server-password'
// or neither for authenticate from ssh-agent
}
},
app: {
// TODO: change app name and path
name: 'xxxx',
path: '../',
servers: {
one: {},
},
buildOptions: {
serverOnly: true,
executable: 'meteor'
},
env: {
ROOT_URL: 'http://xxxx',
MONGO_URL: 'mongodb://mongodb/meteor',
MONGO_OPLOG_URL: 'mongodb://mongodb/local',
},
docker: {
// change to 'abernix/meteord:base' if your app is using Meteor 1.4 - 1.5
image: 'abernix/meteord:node-8.4.0-base',
},
enableUploadProgressBar: true,
deployCheckWaitTime: 120,
},
mongo: {
version: '3.4.1',
servers: {
one: {}
}
},
};
Putty Session
Using username "ubuntu".
Authenticating with public key "imported-openssh-key"
Welcome to Ubuntu 16.04.4 LTS (GNU/Linux 4.4.0-1065-aws x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
Get cloud support with Ubuntu Advantage Cloud Guest:
http://www.ubuntu.com/business/services/cloud
28 packages can be updated.
0 updates are security updates.
New release '18.04.1 LTS' available.
Run 'do-release-upgrade' to upgrade to it.
Last login: Fri Aug 17 22:06:59 2018 from xxxx
ubuntu#xxxx:~$ meteor --version
Meteor 1.7.0.4
ubuntu#xxxx:~$ node -v
v10.9.0
ubuntu#xxxx:~$ mup --version
1.4.5
ubuntu#xxxx:~$ cd xxxx
ubuntu#xxxx:~/xxxx$ cd .deploy
ubuntu#xxxx:~/xxxx/.deploy$ mup status
=> Servers
- xxxx: Ubuntu 16.04
=> Docker Status
- xxxx: 18.06.0-ce Running
=> Meteor Status
- xxxx: created
Created at 2018-08-17T16:17:42.747786756Z
Restarted 0 times
ENV:
- ROOT_URL=http://xxxx
- MONGO_URL=mongodb://mongodb:27017/xxxx
- MONGO_OPLOG_URL=mongodb://mongodb/local
- METEOR_SETTINGS={"public":{}}
- PORT=80
- PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
- METEORD_DIR=/opt/meteord
- NODE_VERSION=8.4.0
Published Ports:
- 80/tcp => 80
App running at http://xxxx:80
- Available in app's docker container: false
- Available on server: false
- Available on local computer: false
=> Mongo Status
running on server xxxx
Restarted 0 times
Running since 2018-08-17T21:41:02.553644287Z
Version: 3.4.1
Connections: 1
Storage Engine: wiredTiger
ubuntu#xxxx:~/xxxx/.deploy$ mup setup
Started TaskList: Setup Docker
[xxxx] - Setup Docker
[xxxx] - Setup Docker: SUCCESS
Started TaskList: Setup Meteor
[xxxx] - Setup Environment
[xxxx] - Setup Environment: SUCCESS
Started TaskList: Setup Mongo
[xxxx] - Setup Environment
[xxxx] - Setup Environment: SUCCESS
[xxxx] - Copying mongodb.conf
[xxxx] - Copying mongodb.conf: SUCCESS
Started TaskList: Start Mongo
[xxxx] - Start Mongo
[xxxx] - Start Mongo: SUCCESS
Next, you should run:
mup deploy
ubuntu#xxxx:~/xxxx/.deploy$ mup deploy --verbose settings settings.json
Building App Bundle Locally
Minifying app code
After several minutes the connection with the instance is lost and I have to restart it, please help me with this problem that i never had before and i need fix soon. Thanks!
I tried "mup deploy --verbose --settings settings.json" command with a very basic app in the same instance of AWS, and get pass the "minifiying" problem, but throw the next error:
Next, you should run:
mup deploy
ubuntu#xxxx/.deploy$ mup deploy --verbose --settings settings.json
Building App Bundle Locally
Started TaskList: Pushing Meteor App
[xxxx] - Pushing Meteor App Bundle to the Server
[xxxx] - Pushing Meteor App Bundle to the Server: SUCCESS
[xxxx] - Prepare Bundle
base: Pulling from abernix/meteord
...
Digest: sha256:5138e4ba3c55cc6fabe0ba859f984e9725599a9f53ed5d759dd4f350770a62b2
Status: Downloaded newer image for abernix/meteord:base
Finished Extracting
Creating Dockerfile
Finished creating Dockerfile
Building image
Sending build context to Docker daemon 67.59MB
Step 1/7 : FROM abernix/meteord:base
# Executing 1 build trigger
---> Running in cf74d5b4fa68
Removing intermediate container cf74d5b4fa68
---> 1f37c25d0989
Step 2/7 : RUN mkdir /built_app || true
---> Running in 1aee7bfde84f
Removing intermediate container 1aee7bfde84f
---> f82f6ad23a8a
Step 3/7 : ENV ROOT_URL=xxxx
---> Running in f26ac397298a
Removing intermediate container f26ac397298a
---> c2eb2e8861f7
Step 4/7 : ENV MONGO_URL=mongodb://mongodb:27017/xxxx
---> Running in be1f89f57b08
Removing intermediate container be1f89f57b08
---> 877e22ea42db
Step 5/7 : ENV MONGO_OPLOG_URL=mongodb://mongodb/local
---> Running in 7801b4f3be1e
Removing intermediate container 7801b4f3be1e
---> 657785f145b4
Step 6/7 : COPY ./ /built_app
---> 3043416670e1
Step 7/7 : RUN cd /built_app/programs/server && npm install --unsafe-perm
---> Running in d2ae3b014734
...
Removing intermediate container d2ae3b014734
---> df4a55163cc2
Successfully built df4a55163cc2
Successfully tagged mup-xxxx:build
Error response from daemon: No such image: mup-xxxx:latest
Total reclaimed space: 0B
[xxxx] - Prepare Bundle: SUCCESS
Started TaskList: Configuring App
[xxxx] - Pushing the Startup Script
[xxxx] - Pushing the Startup Script : SUCCESS
[xxxx] - Sending Environment Variab les
[xxxx] - Sending Environment Variab les: SUCCESS
Started TaskList: Start Meteor
[xxxx] - Start Meteor
using image
Error: No such image: mup-xxxx:previous
Image mup-xxxx:latest
Volume
Removing docker containers. Errors about nonexistent endpoints and containers ar e normal.
Error: No such container: xxxx
Error response from daemon: endpoint xxxx not found
Error: No such container: xxxx-frontend
Error response from daemon: endpoint xxxx-frontend not found
Error: No such container: xxxx-nginx-letsencrypt
Error response from daemon: endpoint xxxx-nginx-letsencrypt not found
Error: No such container: xxxx-nginx-proxy
Error response from daemon: endpoint xxxx-nginx-proxy not found
Finished removing docker containers
0e23b10725796947401ab151a78b2349f32a3779249f3847d20f1b82d2c251a4
Ran abernix/meteord:base
[xxxx] - Start Meteor: SUCCESS
[xxxx] - Verifying Deployment
Container has no IP Address, likely from the app crashing.
Container has no IP Address, likely from the app crashing.
=> Container status:
Container spent too much time restarting.
restarted: 8 times {"Bridge":"","SandboxID":"d97cbb37a87106a3bdeaa51022acabd5e13 66a52317d11fcd75a3593730349bd","HairpinMode":false,"LinkLocalIPv6Address":"","Li nkLocalIPv6PrefixLen":0,"Ports":{},"SandboxKey":"/var/run/docker/netns/d97cbb37a 871","SecondaryIPAddresses":null,"SecondaryIPv6Addresses":null,"EndpointID":""," Gateway":"","GlobalIPv6Address":"","GlobalIPv6PrefixLen":0,"IPAddress":"","IPPre fixLen":0,"IPv6Gateway":"","MacAddress":"","Networks":{"bridge":{"IPAMConfig":nu ll,"Links":null,"Aliases":null,"NetworkID":"081a5c91dc08e96e9a6efc23130e8e602951 1153751498da778dac3c9a8beb9d","EndpointID":"","Gateway":"","IPAddress":"","IPPre fixLen":0,"IPv6Gateway":"","GlobalIPv6Address":"","GlobalIPv6PrefixLen":0,"MacAd dress":"","DriverOpts":null}}} {"Status":"restarting","Running":true,"Paused":fa lse,"Restarting":true,"OOMKilled":false,"Dead":false,"Pid":0,"ExitCode":1,"Error ":"","StartedAt":"2018-08-20T20:08:58.615954182Z","FinishedAt":"2018-08-20T20:08 :58.900441472Z"}
=> Logs:
at require (internal/module.js:12:17)
at Object.<anonymous> (/built_app/main.js:4:1)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
=> Starting meteor app on port:80
/built_app/programs/server/boot.js:49
const { pause } = require("./debug.js");
^
SyntaxError: Unexpected token {
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:373:25)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/built_app/main.js:4:1)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
=> Starting meteor app on port:80
/built_app/programs/server/boot.js:49
const { pause } = require("./debug.js");
^
Module._extensions..js (module.js:416:10)
To see more logs type 'mup logs --tail=200'
[xxxx] x Verifying Deployment: FAIL ED
------------------------------------STDERR------------------------ ------------
Container spent too much time restarting.
at require (internal/module.js:12:17)
at Object.<anonymous> (/built_app/main.js:4:1)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
=> Starting meteor app on port:80
/built_app/programs/server/boot.js:49
const { pause } = require("./debug.js");
^
SyntaxError: Unexpected token {
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:373:25)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/built_app/main.js:4:1)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
=> Starting meteor app on port:80
/built_app/programs/server/boot.js:49
const { pause } = require("./debug.js");
^
SyntaxError: Unexpected token {
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:373:25)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/built_app/main.js:4:1)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
=> Starting meteor app on port:80
/built_app/programs/server/boot.js:49
const { pause } = require("./debug.js");
^
SyntaxError: Unexpected token {
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:373:25)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/built_app/main.js:4:1)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
=> Starting meteor app on port:80
/built_app/programs/server/boot.js:49
const { pause } = require("./debug.js");
^
------------------------------------STDOUT------------------------ ------------
Container has no IP Address, likely from the app crashing.
Container has no IP Address, likely from the app crashing.
Container has no IP Address, likely from the app crashing.
Container has no IP Address, likely from the app crashing.
=> Container status:
restarted: 8 times {"Bridge":"","SandboxID":"d97cbb37a87106a3bdeaa51022a cabd5e1366a52317d11fcd75a3593730349bd","HairpinMode":false,"LinkLocalIPv6Address ":"","LinkLocalIPv6PrefixLen":0,"Ports":{},"SandboxKey":"/var/run/docker/netns/d 97cbb37a871","SecondaryIPAddresses":null,"SecondaryIPv6Addresses":null,"Endpoint ID":"","Gateway":"","GlobalIPv6Address":"","GlobalIPv6PrefixLen":0,"IPAddress":" ","IPPrefixLen":0,"IPv6Gateway":"","MacAddress":"","Networks":{"bridge":{"IPAMCo nfig":null,"Links":null,"Aliases":null,"NetworkID":"081a5c91dc08e96e9a6efc23130e 8e6029511153751498da778dac3c9a8beb9d","EndpointID":"","Gateway":"","IPAddress":" ","IPPrefixLen":0,"IPv6Gateway":"","GlobalIPv6Address":"","GlobalIPv6PrefixLen": 0,"MacAddress":"","DriverOpts":null}}} {"Status":"restarting","Running":true,"Pa used":false,"Restarting":true,"OOMKilled":false,"Dead":false,"Pid":0,"ExitCode": 1,"Error":"","StartedAt":"2018-08-20T20:08:58.615954182Z","FinishedAt":"2018-08- 20T20:08:58.900441472Z"}
=> Logs:
To see more logs type 'mup logs --tail=200'
------------------------------------------------------------------ ------------
I am trying to run one of the sample projects using appjs which is present over here https://github.com/appjs/appjs/tree/master/examples. I am using the latest version of node.js (v4.1.0
) on Windows (64 bit machine)
When I try and run the example using the below command on Command Prompt
node --harmony index.js
I get an error as follows,
Error: AppJS requires Node is run with the --harmony command line flag
at Object.<anonymous> (F:\programs\appjs_examples\node_modules\appjs\lib\ind
ex.js:2:9)
at Module._compile (module.js:434:26)
at Object.Module._extensions..js (module.js:452:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (F:\programs\appjs_examples\octosocial\index.js:1:73)
at Module._compile (module.js:434:26)
at Object.Module._extensions..js (module.js:452:10)
I tried searching for this issue but I couldn't find a solution. Can anyone tell me how to use node.js with the harmony flag?
UPDATE
My index.js looks like this
var app = require('appjs'),
github = new (require('github'))({ version: '3.0.0' }),
KEY_F12 = process.platform === 'darwin' ? 63247 : 123;
app.serveFilesFrom(__dirname + '/assets');
var window = app.createWindow({
width: 460,
height: 640,
resizable: false,
disableSecurity: true,
icons: __dirname + '/assets/icons'
});
window.on('create', function(){
window.frame.show();
window.frame.center();
});
window.on('ready', function(){
var $ = window.$,
$username = $('input[name=username]'),
$password = $('input[name=password]'),
$info = $('#info-login'),
$label = $info.find('span'),
$buttons = $('input, button');
$(window).on('keydown', function(e){
if (e.keyCode === KEY_F12) {
window.frame.openDevTools();
}
});
$username.focus();
$('#login-form').submit(function(e){
e.preventDefault();
$info.removeClass('error').addClass('success');
$label.text('Logging in...');
$buttons.attr('disabled', true);
github.authenticate({
type: 'basic',
username: $username.val(),
password: $password.val()
});
github.user.get({}, function(err, result) {
if (err) {
$info.removeClass('success').addClass('error');
$label.text('Login Failed. Try Again.');
$buttons.removeAttr('disabled');
} else {
loggedIn(result);
}
});
});
function loggedIn(result){
$label.text('Logged in!');
$('#user-avatar').append('<img src="'+result.avatar_url+'" width="64" height="64">');
$('#user-name').text(result.name);
$('#login-section').hide();
$('#profile-section').show();
['Followers', 'Following'].forEach(function(type){
github.user['get'+type]({ user: result.login }, populate.bind(null, type.toLowerCase()));
});
}
Now with v0.12 of Node.js I get below error
F:\softwares\Node.js_v0.12\node_modules\appjs\lib\index.js:2
throw new Error ('AppJS requires Node is run with the --harmony command line
Error: AppJS requires Node is run with the --harmony command line flag
at Object.<anonymous> (F:\softwares\Node.js_v0.12\node_modules\appjs\lib\ind
ex.js:2:9)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (F:\softwares\Node.js_v0.12\index.js:1:73)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
Just tested your code out locally with node v0.12.7 and v4.0.0. Looks like the node_modules/appjs/lib/index.js check makes sure that proxy is enabled no matter what.
By default the --harmony flag does not enable proxies. However you can use --harmony_proxies.
To help you understand what is happening:
Open node in your terminal, Then type Proxy. You will get 'Proxy is not defined'.
Now, open node --harmony in your terminal and do the same. You will get the same output.
Now, with node --harmony-proxies. Bam, you get an empty object.
You should be able to run this with v4.x.x however, you will still need the proxies flag for harmony.
When the merge happened with node.js and io.js for v4 they released a page of ES6 features that are shipped if you are using 4.x.x. https://nodejs.org/en/docs/es6/
https://github.com/appjs/appjs is deprecated btw, but once you pass the module's test of features, it will require 32bit ;)
Edit:
To properly run your app use the following:
node --harmony-proxies index.js
Here is a screenshot to show the expected output from step 3 above.
I'm on Windows 10 TP build 9926, using nodejs. I want to be able to import a Javascript into a current session of nodejs that is running on Windows command prompt so that functions from the imported script can be called from within the REPL. How can I achieve that? My attempt of "import" and "require" did not succeed.
I tried the following in a nodejs session running from the directory that has the "learn.js" javascript;
var n = require("learn.js")
Then got the following error message:
Error: Cannot find module 'learn.js'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:278:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at repl:1:9
at REPLServer.defaultEval (repl.js:132:27)
at bound (domain.js:254:14)
at REPLServer.runBound [as eval] (domain.js:267:12)
at REPLServer.<anonymous> (repl.js:279:12)
at REPLServer.emit (events.js:107:17)
The learn.js file needs to look like the following:
"use strict";
module.exports.myfunc1 = function() {
console.log("Hi there.");
}
module.exports.myfunc2 = function() {
console.log("Goodbye.");
}
Also, you must require it like this:
var n = require('./learn.js');
or
var n = require('./learn');
You must make the path relative to where you are running the REPL. Node won't automatically check the local directory.
I'm trying to install the Now.js module for Node.js. It gets installed, but it doesn't work. When I install it, here's what I get:
eustace#eustace-desktop:/var/www/nowjs$ sudo npm install now -g
> node-proxy#0.5.1 install /usr/local/lib/node_modules/now/node_modules/node-proxy
> make
BUILDING: C++ Component
Checking for program g++ or c++ : /usr/bin/g++
Checking for program cpp : /usr/bin/cpp
Checking for program ar : /usr/bin/ar
Checking for program ranlib : /usr/bin/ranlib
Checking for g++ : ok
Checking for node path : not found
Checking for node prefix : ok /usr/local
'configure' finished successfully (0.038s)
Waf: Entering directory `/usr/local/lib/node_modules/now/node_modules/node-proxy/src/build'
[1/2] cxx: node-proxy.cc -> build/default/node-proxy_1.o
[2/2] cxx_link: build/default/node-proxy_1.o -> build/default/node-proxy.node
Waf: Leaving directory `/usr/local/lib/node_modules/now/node_modules/node-proxy/src/build'
'build' finished successfully (0.909s)
now#0.7.4 /usr/local/lib/node_modules/now
├── node-proxy#0.5.1
└── socket.io#0.8.2
I'm trying to get the example working (http://nowjs.com/doc/example), but when I run helloworld_server.js in terminal, here's what I get:
eustace#eustace-desktop:/var/www/nowjs$ node helloworld_server.s
node.js:134
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: Cannot find module '/var/www/nowjs/helloworld_server.s'
at Function._resolveFilename (module.js:317:11)
at Function._load (module.js:262:25)
at Array.<anonymous> (module.js:421:10)
at EventEmitter._tickCallback (node.js:126:26)
eustace#eustace-desktop:/var/www/nowjs$ node helloworld_server.js
node.js:134
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: Cannot find module 'now'
at Function._resolveFilename (module.js:317:11)
at Function._load (module.js:262:25)
at require (module.js:346:19)
at Object.<anonymous> (/var/www/nowjs/helloworld_server.js:7:13)
at Module._compile (module.js:402:26)
at Object..js (module.js:408:10)
at Module.load (module.js:334:31)
at Function._load (module.js:293:12)
at Array.<anonymous> (module.js:421:10)
at EventEmitter._tickCallback (node.js:126:26)
I'm using Node.js v0.4.11 and Ubuntu 11.04. I tried doing 'export NODE_PATH="/usr/local/lib/node"', but it didn't help.
How do I fix this?
The problem was that I mistyped helloworld_server.js. I wasted around 6 hours trying to fix this, what a stupid mistake :)