Node-webkit How do I start an express (more accurate MEANJS) project?
General online is to teach you Node-webkit from an HTML file to start the ~ when we are using an express project to let Node-webkit start, it is very few people wrote about ~
So, I'm going to write down here how I got node-webkit to start an express service!
Refer to official information:
Https://github.com/nwjs/nw.js/wiki/NW.js-use-express-and-similar-web-frameworks
From the official documentation, it looks like you just need to configure the main property as a URL, node-main the script configured to start the Express service.
The code looks like this:
{ ... " Node-main ":"./app/server.js", "main " " http://localhost:3000 " , ...}
The above code is the Package.json file for the Node-webkit project (not node Package.json), which node-main
is our express startup script, which main
is after we start Express, The first page that Node-webkit will visit.
Well, is it all right to be configured like this?
We try to start a bit ~ we will find that the service did not start!!!
Strange ~ How did the service not start up?
We tried to start the Express project with the terminal to see if there was a problem with the Express project configuration.
Such as:
Unexpectedly error said no E:\webstormWorkspace\cnote\config\assets\default
module found ~
Carefully look at the above error path address ~ eh?
My path should not be: E:\webstormWorkspace\cnote \app \config\assets\default?
How can the directory be missing from the path?
It suddenly occurred to me that when Node-webkit started my cnote project, it started from the Cnote directory, then the process.cwd()
working directory address of the global return of Nodejs was E:\webstormWorkspace\cnote
; then we looked at the file that was just error, and found that the file used a lot ofprocess.cwd()
Path.join (PROCESS.CWD (), ' modules/*/client/')
, because I can now see the global in our current cnote project; process.cwd () &NBSP
The result returned is: E:\webstormWorkspace\cnote
, not e:\ Webstormworkspace\cnote\app
, so that the file path that was introduced is wrong ~
global object process &NBSP
provides process.chdir (directory)
, this method will change the current working directory of our project, that is, we say to Nodejs: "Hey, our working directory is not that, it's this ... ~".
Process reference:
Https://nodejs.org/api/process.html#process_process_chdir_directory
We only need to modify process.cwd()
the current working directory process.chdir(directory)
before invoking the method ~
Such as:
Then we execute the next Startcnote.bat script again,
The discovery service started properly ~
Cloud Note Development record two: Node-webkit How to start an express (more accurate MEANJS) project?