Like "startar" a Node server?

Asked

Viewed 4,489 times

5

I installed Node, created the environment variable (NODE_ENV) speed value.

When I installed and configured, I printed out a arquivo.js with hellow world and it worked.

Today, I want to start the server, but I can’t. I’ve set node_env and the environment variable is ok. I already typed in the terminal node -v, but does not show version, Windows does not recognize this command.

How do I start and keep the Node server running?

  • 1

    I don’t use text formatting much because I am visually impaired and can’t visually track every formatting, style, etc. What well to do is to choose font, color, minimal things.

3 answers

5


Probably, although you create the NODE_ENV variable, it is not in the Windows PATH, this is necessary for Windows to recognize the command you are running, in case Node -v.

Do this in the advanced system properties, in the Advanced tab, environment variables.

Another option, is to set this via command line, I do this with a BAT, to simplify the process, so only select the variables when really need. Below is an example of how the BAT would look:

SET NODE_ENV=<caminho_node>
SET PATH=%PATH%;%NODE_ENV%

Note that in this case the environment variables will be valid only for the current session. So do BAT, save to Node’s working directory, and before you start running Node, run bat.

3

0

One option to create a server without much difficulty is to use the modules: express-Generator on Node.

The express-Enerator can be installed by typing the command:

$ npm install express-generator -g

Creating the structure of the project:

$ express exemplo-express -e ejs

A similar structure will be created in your root directory.

exemplo-express/
├── bin/
├── public/
│   ├── images/
│   ├── javascripts/
│   ├── stylesheets/
├── routes/
│   ├── index.js
│   ├── users.js
├── views/
│   ├── error.ejs
│   ├── index.ejs
├── app.js
├── package.json

After that, you will need to install all the dependencies that are in package.json.

{
  "name": "myapp",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}

Papa install the dependencies just type in the console the following command:

$ npm install

Once done, your server will already be created and ready to use and the server can be started with the command:

$ npm start

Browser other questions tagged

You are not signed in. Login or sign up in order to post.