Generate app.js file with express processing on server.js

I use the command express -e myAppNameto launch my application.

By default, this gives me a file with a name app.jsthat, as you all know, contains all my server logic, middleware, etc.

I tried changing the name app.jsto server.js, and after that I got this error.Error: Cannot find module '../app'

So, I go to the bin directory and wwwchange var app = require('../app');to inside the file var app = require('../server');, however this does not fix the error so that it is saved.

I am relatively new to web development (3 months) and almost 2 months working with the MEAN stack. I looked around a bit and did not find anyone who would try to change the file names as I want.

+4
source share
1 answer

What you did is correct (i.e. updating the path in bin \ www).

However, you must start your express application using npm start

In general, npm applications allow you to specify a command inside the json package that will launch your application, and this is the first thing to watch.

For a pronounced generated image, this should look like this:

{
  "scripts" : {
    "start" : "node bin/www"
  }
}

If you want to change it and pass arguments, then all you need to do is update the package.json file and your end users will not be affected.

npm startprovides users of your program with a consistent way to launch the application no matter what file names or parameters you change

development setting

, nodemon , :

nodemon bin/www

script :

{
  "scripts" : {
    "start" : "node bin/www",
    "devel" : "nodemon bin/www"
  }
}

nodemon :

npm run devel

, nodemon.

+4

Source: https://habr.com/ru/post/1609243/


All Articles