I am new in development field.
I have already made an app in create-react-app.
But now I have been asked to submit json.config file..
It is mentioned that -
The file must be called config.json and must be stored in the root level of your project.
Here is the format of the configuration file:
{
"install": "npm install",
"run": "npm start",
"port": 3000
}
I am unable to find it in my project folders and dependency folders and files.
Create-React-App creates this file for you under the hood. So you don't have to setup it. You can open the terminal and write npm install and after npm start. That will open your web app in http://localhost:3000.
More details https://create-react-app.dev/docs/available-scripts
Edit: Dependencies should be inside the package.json in the root directory.
I am new in nodejs framework .I read the tutorial, but I want to know how to create a build in node js, in other words I need a script which create my build folder.
I follow these steps
create index.js in root directory add some code.
then add this line of code
import express from 'express';
const app = express();
app.listen(3000,function () {
console.log(`app is listening on 3000`)
})
in my package.json I added start and build script
"scripts": {
"start": "nodemon ./index.js --exec babel-node -e js",
"build": "mkdir dist && babel src -s -d dist"
},
when I do npm run start .my application run fine and I am able to debug also.
Now I want to deploy this application on production Need build.so how to generate build using babel
when I run npm run build I am getting error
src doesn't exist
You 'build' command is like 'mkdir ... && babel src ....', then in the photo it does not have a src folder. So you can simply create a src folder and move index.js to src/, or change the command to 'mkdir dist && babel ./ -s -d dist'. I did not test, but it should work.
I'm studying MEAN 2.0 . I need to do "ng build" before running "node server.js".
I would like to ask if do I need to do (ng build) everytime I changed something in my angular side? Because when I'm using only angular-cli, when I changed something and my server is still running. It will show the changes. I tried to change something but when I re-run my node server nothing happens.
Yes you need to do ng build before running node server.js.
ng serve :- serves on a server,
node server.js :- doesnt serve on the same port, it runs on the port you define in your server.js, it reads from the build folder, which will need updated fies.
Live reload wont work :(
You can
1. write tasks for it
2. write script in package.json which does ng build && node server.js
If you arranged your folder structure to be:
|_server
|_ server.js
|_ public (angular-cli project)
|_ dist
|_ src
|_ package.json (client)
|_package.json(server)
Considering you've the default angular-cli package.json,
Add concurrently using npm:
npm install concurrently --save-dev
All you would need is to add those scripts in server package.json:
"scripts": {
"client":"cd public && ng build",
"server":"ndoe ./server/server",
"start":"concurrently --kill-others \"npm run client\" \"npm run server\""
}
Now, all you have to do is:
npm run start
I installed NodeJS (4.4.5) and then proceed to install nodemon (1.9.2) as well,
I follow all the instrucctions of instalation (npm install -g nodemon)
I created a new folder, inside I have my server.js with some basic code:
var http = require('http');
http.createServer(function (request, response){
response.writeHead( 200, {'Content-Type': 'text/plain'} );
response.write("Hello world");
response.end();
}).listen(3000, 'localhost');
console.log('http://localhost:3000');
So when I run in my console "nodemon server.js" I get this:
[nodemon] 1.9.2
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node server.js`
http://localhost:3000
(Which means that is running fine)
But when I make some changes in my server.js, It doesn't restart the server
What could be the issue?
In some networked environments (such as a container running nodemon reading across a mounted drive), you will need to use the legacyWatch: true which enabled Chokidar's polling.
Via the CLI, use either --legacy-watch or -L for short:
nodemon -L
I had the same issue on nodemon 1.9.2 : 0 files were watched by nodemon
(try verbose mode nodemon server.js -V to get more information)
After some research, this issue was due to my root directory name :
My root directory was named "mysite.git" thus nodemon was watching 0 file. I had renamed my root directory without the dot and nodemon now works as expected.
Remove all special characters from your root directory and nodemon should work as expected.
You can try running like this nodemon -L yourapp.js, something like that:
"scripts": {
"start": "node index.js",
"dev": "nodemon -L index.js "
}
And run command:
npm run dev
This worked for me!
I just hit what seemed to be the same issue where I would make changes to my code and save them but nodemon wouldn't restart my server. The only way I could update was via 'rs' in the console. I ended here looking for a solution but then decided to just re-install nodemon as there was no good explanation for why it wasn't working:
npm uninstall nodemon
npm install nodemon
After reinstalling the automatic restart on code change worked.
Nodemon uses SIGUSR2 signal for restarting the server, cross-check if your server is overriding the functionality of this process signal.
In my case, I was using heapdump module, which was resetting this signal, hence I started the server using:-
env NODE_HEAPDUMP_OPTIONS=nosignal nodemon app.js
This worked for me.
Edit the package.json file like this :
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "nodemon server.js",
},```
This may help you.
Just Make Sure to add to scripts -> start --legacy-watch ./app
"scripts": {
"start": "nodemon --legacy-watch ./app ./bin/www "
},
I had the same problem. I tried uninstalling nodemon, didn't work. You can try and uninstall nodemon globally, if it works. It didn't work in my case, so what I did is I deleted all the node modules from my system. They will be located at C:/users/user/AppData/Roaming/npm. I even reinstalled node into my system and then installed nodemon, then it worked.
I had the same problem and I solved it adding the path C:\Windows\System32 to the system environment, after that, I had to restart Visual studio code and it worked!...
Reference: https://www.youtube.com/watch?v=a9fIZViTNEA
if you are on windows use Powershell, not WSL. If you want to use WSL, you have to move your project directory to the WSL home directory OR use nodemon -L on the command line.
solve it by adding the path
C:\Windows\System32
to the system environment
Source: https://www.youtube.com/watch?v=a9fIZViTNEA
I found a solution on YouTube. So, the solution is:
Copy this path:
C:\Windows\System32
Go into 'computer/This Pc' properties then into 'Advance System Settings/System Settings'.
Then click on 'Environment variable' Button.
Then double click on 'Path' in User Variables section.
Then click on 'New' and paste this path :
C:\Windows\System32
I have problem trying to run node app in Windows 7.I have installed express generator globally and with it help created a test_app directory and installed the modules. In the package.json scripts look like this:
"scripts": {
"start": "node ./bin/www"
}
However, when i run npm start it just returns this in console:
test_app#0.0.1 start C:\work\test_app
node ./bin/www
If i try to run node app.js nothing happens. Before there wasn't problems with the express, until the moment when i had to install express-generate globally.